mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 20:45:58 +01:00
refactor
This commit is contained in:
@@ -105,27 +105,11 @@ function setupExpressApp(app) {
|
|||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(useragent.express());
|
app.use(useragent.express());
|
||||||
|
|
||||||
var cookie = {
|
|
||||||
maxAge: 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 14)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (meta.config.cookieDomain) {
|
|
||||||
cookie.domain = meta.config.cookieDomain;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nconf.get('secure')) {
|
|
||||||
cookie.secure = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (relativePath !== '') {
|
|
||||||
cookie.path = relativePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
app.use(session({
|
app.use(session({
|
||||||
store: db.sessionStore,
|
store: db.sessionStore,
|
||||||
secret: nconf.get('secret'),
|
secret: nconf.get('secret'),
|
||||||
key: 'express.sid',
|
key: 'express.sid',
|
||||||
cookie: cookie,
|
cookie: setupCookie(),
|
||||||
resave: true,
|
resave: true,
|
||||||
saveUninitialized: true
|
saveUninitialized: true
|
||||||
}));
|
}));
|
||||||
@@ -146,6 +130,37 @@ function setupFavicon(app) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function setupCookie() {
|
||||||
|
var cookie = {
|
||||||
|
maxAge: 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 14)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (meta.config.cookieDomain) {
|
||||||
|
cookie.domain = meta.config.cookieDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nconf.get('secure')) {
|
||||||
|
cookie.secure = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var relativePath = nconf.get('relative_path');
|
||||||
|
if (relativePath !== '') {
|
||||||
|
cookie.path = relativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cookie;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cacheStaticFiles() {
|
||||||
|
if (global.env === 'development') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.enable('cache');
|
||||||
|
app.enable('minification');
|
||||||
|
}
|
||||||
|
|
||||||
function initializeNodeBB(callback) {
|
function initializeNodeBB(callback) {
|
||||||
var skipJS;
|
var skipJS;
|
||||||
var fromFile = nconf.get('from-file') || '';
|
var fromFile = nconf.get('from-file') || '';
|
||||||
@@ -157,7 +172,6 @@ function initializeNodeBB(callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(cacheStaticFiles),
|
|
||||||
async.apply(meta.themes.setupPaths),
|
async.apply(meta.themes.setupPaths),
|
||||||
function(next) {
|
function(next) {
|
||||||
plugins.init(app, middleware, next);
|
plugins.init(app, middleware, next);
|
||||||
@@ -189,16 +203,6 @@ function initializeNodeBB(callback) {
|
|||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function cacheStaticFiles(callback) {
|
|
||||||
if (global.env === 'development') {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
app.enable('cache');
|
|
||||||
app.enable('minification');
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
function listen() {
|
function listen() {
|
||||||
var port = parseInt(nconf.get('port'), 10);
|
var port = parseInt(nconf.get('port'), 10);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user