本文整理汇总了TypeScript中cookie-parser.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
module.exports = function(app) {
var env = config.env;
//Compression middleware (should be placed before express.static)
//The middleware will attempt to compress response bodies for all request that traverse through the middleware, based on the given options.
app.use(compression({
//The byte threshold for the response body size before compression is considered for the response, defaults to 1kb.
threshold: 512
}));
//app.use(passport.initialize());
app.use(express.static(path.join(config.root, 'client')));
app.set('appPath', 'client');
app.use(multer().array('image', 1));
app.set('view engine', 'html');
//The extended option allows to choose between parsing the URL-encoded data
//with the querystring library (when false) or the qs library (when true).
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// CookieParser should be above session
app.use(cookieParser());
app.use(cookieSession({ secret: config.secrets.cookie }));
app.use(compression());
//app.use(morgan('dev'));
//app.use(passport.initialize());
app.use(express.static(path.join(config.root, 'client/build')));
app.use(express.static(path.join(config.root, 'node_modules')));
app.set('appPath', 'client/build');
// use passport session
app.use(passport.initialize());
app.use(session({
secret: config.secrets.session,
resave: true,
saveUninitialized: true,
store: new mongoStore({ mongooseConnection: mongoose.connection })
}));
// Use winston on production
//var log = 'dev';
var log;
if (env !== 'development') {
log = {
stream: {
write: message => winston.info(message)
}
};
} else if (env === 'development') {
log = 'dev'
}
// Don't log during tests
// Logging middleware
if (env !== 'test') app.use(morgan(log));
if (env === 'development' || env === 'test') {
app.use(require('errorhandler')());
}
if (env !== 'test') {
app.use(csrf());
// This could be moved to view-helpers :-)
app.use(function(req, res, next) {
res.locals.csrf_token = req.csrfToken();
next();
});
}
};
示例2: require
import https = require('https');
import http = require('http');
import express = require('express');
var logger = require('connect-logger');
var cookieParser = require('cookie-parser');
import session = require('express-session');
var FileStore = require('session-file-store')(session);
var expressHandlebars = require('hbs');
var controllerFactory = require('./controllers/index');
// setup express
var app = express();
app.use(logger());
app.use(cookieParser('8d705e4b-c142-420e-955a-a1a58263b6bd'));
app.use(session({
store: new FileStore(),
secret: '13603e53-f0af-41dd-b020-dbf5c9e7768e',
resave: false,
saveUninitialized: true
}));
// configure handlebars as the view engine
expressHandlebars.registerPartials(__dirname + '/views');
// configure express to use handlebars as the view engine
app.set('view engine', 'hbs');
// change express default where to look for views on the server
app.set('views', __dirname + '/views');
示例3: setupBodyParsing
function setupBodyParsing(app): void {
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
}
示例4: require
let logger = require('morgan');
let cookieParser = require('cookie-parser');
let bodyParser = require('body-parser');
let app = express();
// view engine setup
app.set('views', path.join(__dirname, '../views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(require('node-sass-middleware')({
src: path.join(__dirname, '../public'),
dest: path.join(__dirname, '../public'),
indentedSyntax: false,
sourceMap: true
}));
//
// connect to database and register models
///////////////////////////////////////////////////////////
import * as db from './models/mongooseModels';
//
// serve static files
///////////////////////////////////////////////////////////
示例5: function
constructor(config : IServerConfig) {
this.config = config;
mongoose.Promise = promise;
mongoose.connect(this.config.dbURI, function (err) {
if (err) {
return console.log('Cannot connect to database', err);
}
return console.log('Database connected.');
});
this.app = express();
// view engine setup
this.app.set('views', path.join(__dirname, 'views'));
this.app.set('view engine', 'jade');
// use compression
this.app.use(compression());
// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
this.app.use(logger('dev'));
this.app.use(cookieParser());
this.app.use(bodyParser.json({ limit: '50mb'}));
this.app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
this.app.use(express.static(path.join(__dirname, 'public'), {maxAge: 3000000000}));
this.app.use(accessController.statusChecker);
this.app.use('/', routes);
this.app.use('/users', users);
this.app.use('/comics', comics);
this.app.use('/comics/edit', express.static(path.join(__dirname, 'public')));
this.app.use('/comics/canvas', express.static(path.join(__dirname, 'public')));
this.app.use('/create', express.static(path.join(__dirname, 'public')));
this.app.use('/canvas', express.static(path.join(__dirname, 'public')));
// catch 404 and forward to error handler
this.app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (this.app.get('env') === 'development') {
this.app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
this.app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
}
示例6: function
export var init = function() {
var app = express();
// Compress content
app.use(compression({
threshold: 512
}));
// view engine setup
app.set('views', path.join(__dirname, '../../views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(morgan('dev', {
stream:BunyanStream
}));
app.use(bodyParser.json({limit: '128mb'}));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, '../../public'), {maxAge: 0}));
var mongoStore = new MongoStore({
mongooseConnection: mongoose.connection,
clear_interval: 3600
});
app.use(session({
secret: options.sessionSecret,
saveUninitialized:true,
resave:true,
store: mongoStore
}));
// Remember Me middleware
app.use( function (req, res, next) {
if ( req.method == 'POST' && req.url == '/login' ) {
if ( req.body.rememberme ) {
req.session.cookie.maxAge = 90*24*60*60*1000; // Rememeber 'me' for 90 days
} else {
req.session.cookie.expires = false;
}
}
next();
});
PassportHandler.init(app);
app.get('/', function(req,res) {
if (req.isAuthenticated()) {
res.redirect(options.baseUrl + '/view');
} else {
res.redirect(options.baseUrl + '/login');
}
});
app.use('/view', ViewRoute);
app.use('/service',ServiceRoute);
ShareJSHandler.init(app, mongoStore);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
res.status(404);
res.send("404 - "+req.path+" Not Found");
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
return app;
};