本文整理汇总了TypeScript中cookie-parser.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript cookie-parser.default方法的具体用法?TypeScript cookie-parser.default怎么用?TypeScript cookie-parser.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cookie-parser
的用法示例。
在下文中一共展示了cookie-parser.default方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: start
export default function start(serverDataPath: string) {
dataPath = serverDataPath;
SupCore.log(`Using data from ${dataPath}.`);
process.on("uncaughtException", onUncaughtException);
loadConfig();
const { version, superpowers: { appApiVersion: appApiVersion } } = JSON.parse(fs.readFileSync(`${__dirname}/../package.json`, { encoding: "utf8" }));
SupCore.log(`Server v${version} starting...`);
fs.writeFileSync(`${__dirname}/../public/superpowers.json`, JSON.stringify({ version, appApiVersion, hasPassword: config.server.password.length !== 0 }, null, 2));
// SupCore
(global as any).SupCore = SupCore;
SupCore.systemsPath = path.join(dataPath, "systems");
// List available languages
languageIds = fs.readdirSync(`${__dirname}/../public/locales`);
languageIds.unshift("none");
// Main HTTP server
mainApp = express();
mainApp.use(cookieParser());
mainApp.use(handleLanguage);
mainApp.get("/", (req, res) => { res.redirect("/hub"); });
mainApp.get("/login", serveLoginIndex);
mainApp.get("/hub", enforceAuth, serveHubIndex);
mainApp.get("/project", enforceAuth, serveProjectIndex);
mainApp.use("/projects/:projectId/*", serveProjectWildcard);
mainApp.use("/", express.static(`${__dirname}/../public`));
mainHttpServer = http.createServer(mainApp);
mainHttpServer.on("error", onHttpServerError.bind(null, config.server.mainPort));
io = socketio(mainHttpServer, { transports: [ "websocket" ] });
// Build HTTP server
buildApp = express();
buildApp.get("/", redirectToHub);
buildApp.get("/systems/:systemId/SupCore.js", serveSystemSupCore);
buildApp.use("/", express.static(`${__dirname}/../public`));
buildApp.get("/builds/:projectId/:buildId/*", (req, res) => {
const projectServer = hub.serversById[req.params.projectId];
if (projectServer == null) { res.status(404).end("No such project"); return; }
let buildId = req.params.buildId as string;
if (buildId === "latest") buildId = (projectServer.nextBuildId - 1).toString();
res.sendFile(path.join(projectServer.buildsPath, buildId, req.params[0]));
});
buildHttpServer = http.createServer(buildApp);
buildHttpServer.on("error", onHttpServerError.bind(null, config.server.buildPort));
loadSystems(mainApp, buildApp, onSystemsLoaded);
// Save on exit and handle crashes
process.on("SIGINT", onExit);
process.on("message", (msg: string) => { if (msg === "stop") onExit(); });
}
示例2: configureApp
configureApp() {
let host = nconf.get("HostInfo");
let corsOptions = {
origin: host.SPAUrl,
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true,
preflightContinue: false
};
// uncomment after placing your favicon in /public
this.app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
this.app.use(cors(corsOptions));
this.app.use(logger('dev'));
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({ extended: false }));
this.app.use(cookieParser());
this.app.use(session({ secret: 'hakans planner hackathon', resave: false, saveUninitialized: false }));
this.app.use(express.static(path.join(__dirname, 'public')));
// setup view engine
this.app.set('views', path.join(__dirname, 'views'));
this.app.set('view engine', 'jade');
}
示例3: bootstrap
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.use(
session({
secret: 'No sera de tomar un tragito',
sesave: false,
saveUninitialixed: true,
cookie: {
secure:false
},
name:'server-session-id',
store: new FileStore()
})
);
app.use(cookieParser(
'me gustan los tacos', // secreto
{ // opciones
}
));
app.set('view engine', 'ejs');
app.use(
express.static('publico')
);
// /public/texto.txt
// localhost:3000/texto.txt
// /public/ejemplo/texto.txt
// localhost:3000/ejemplo/texto.txt
await app.listen(3000);
}
示例4: bootstrap
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.use(
session ({
secret:'No sera de tomar un traguito',
resave: false,
saveUninitialized: true,
cookie: {secure: false},
name:'server-session-id',
store: new FileStore()
})
);
app.use(cookieParser(
'me gustan los tacos', // secreto
{ // opciones
}
));
app.set('view engine', 'ejs');
await app.listen(3000);
}
示例5: constructor
constructor() {
this.app = loopback();
this.app.use(cookieParser());
this.app.start = async () => {
// start the web server
const models = this.app.models();
const model = models[0] as (typeof loopback.PersistedModel);
const data = await model.findOne<TestModel>();
if (data) {
console.dir(data.name);
}
model.findOne<TestModel>({}, (err, instance) => {
if (err) {
console.dir(err);
}
console.dir(instance.name);
});
};
}
示例6: express
'DELETE /bulk': {
type: ActionType.Destroy,
byId: false,
byList: true,
authorization: {permission: Permissions.UserCreate},
},
},
},
'/v1/posts': {
modelName: ModelId.Post,
routes: {
'GET /': {type: ActionType.List},
'POST /search': {type: ActionType.List, expectQueryIn: ValidateIn.Body},
'POST /': {type: ActionType.Create},
'GET /:id': {type: ActionType.Read},
'PUT /:id': {type: ActionType.Update},
'DELETE /:id': {type: ActionType.Destroy},
},
},
}
export const app: express.Express = express()
if (typeof (global as any).it === 'undefined') app.use(logger('short'))
app.use(json({strict: false}))
app.use(cookies())
app.use(authenticate(authConf))
app.use(createAndMergeRouters(kiln, routerMap).router)
app.use(createHandlePromiseMiddleware())
app.use(createHandleErrorMiddleware())
示例7: express
import { enableProdMode } from '@angular/core';
// Angular 2 Universal
import { expressEngine } from 'angular2-universal';
// enable prod for faster renders
enableProdMode();
const app = express();
const ROOT = path.join(path.resolve(__dirname, '..'));
// Express View
app.engine('.html', expressEngine);
app.set('views', __dirname);
app.set('view engine', 'html');
app.use(cookieParser('Angular 2 Universal'));
app.use(bodyParser.json());
// Serve static files
app.use('/assets', express.static(path.join(__dirname, 'assets'), {maxAge: 30}));
app.use(express.static(path.join(ROOT, 'dist/client'), {index: false}));
import { getOptions, castVote } from './backend/api';
// Our API for demos only
app.get('/data/options', getOptions);
app.post('/data/options/vote/:beerId', castVote)
import { ngApp } from './main.node';
// Routes with html5pushstate
// ensure routes match client-side-app
示例8: Date
var str: string = "\r\n" + new Date().toLocaleString() + "\r\n";
str += JSON.stringify(err);
fs.appendFile(SERVER + '/error.log', str);
};
////////// Types only/////////////
import {Request} from "express";
import {Response} from "express";
import {Express} from "express";
///////////////////////////////////////
const app:Express = express();
// configure our app to use bodyParser(it let us get the json data from a POST)
app.use(cookie());
app.use(session({
resave: false, // don't save session if unmodified
saveUninitialized: false, // don't create session until something stored
secret:'somesecrettokenhere'
}));
app.use('/api',bodyParser.urlencoded({extended: true}));
app.use('/api',bodyParser.json());
app.use(express.static(WWW));
app.get('/', function(req:express.Request, res:express.Response){
res.sendFile('indexts.html',{ 'root':WWW});
});
示例9: express
import {DbConnection} from "./database";
import {credentials} from "./secret";
import * as bodyParser from "body-parser";
import {UserController} from "./controllers/userController";
import {LoanController} from "./controllers/loanController";
import {BookCopyController} from "./controllers/bookCopyController";
let app = express();
let api = express();
app.use("/api", api);
app.use(require("morgan")("dev"));
DbConnection.initConnection(app.get("env"));
app.set("port", process.env.PORT || 5000);
app.use(cookieParser(credentials.cookieSecret));
app.use(expressSession());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
//TODO.md: domains are deprecated and will be removed in the future,
//find an alternative
app.use(function (req, res, next) {
console.log("heeyy it works!");
var domain = require("domain").create();
domain.on("error", function (err) {
console.error("Domain error caught! \n", err.stack);
try {
setTimeout(function () {
console.error("Failsafe shutdown");
示例10: express
////////////////////////////////////
process.on('uncaughtException', (err: Error) => {
console.error(err)
process.exit(1)
})
process.on('unhandledRejection', (reason: string, p: Promise<any>) => {
console.error('Unhandled Rejection at: Promise', p, 'reason:', reason)
process.exit(1)
})
////////////
var app = express()
app.use(cookie_parser())
////////////
app.get('/', (req, res) => {
res.sendFile('index.html', { root: __dirname })
})
app.get('/client.js', (req, res) => {
res.sendFile('client.js', { root: __dirname + '/..' })
})
app.get('/best-locales', best_locales_middleware)
app.get('/set-locale', (req, res) => {
const locale: BCP47Locale | undefined = normalize_and_validate_bcp47_locale(req.query.lang)