|
|
@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var path = require('path'),
|
|
|
|
var path = require('path'),
|
|
|
|
fs = require('fs'),
|
|
|
|
fs = require('fs'),
|
|
|
|
nconf = require('nconf'),
|
|
|
|
nconf = require('nconf'),
|
|
|
@ -9,11 +12,7 @@ var path = require('path'),
|
|
|
|
cluster = require('cluster'),
|
|
|
|
cluster = require('cluster'),
|
|
|
|
|
|
|
|
|
|
|
|
emailer = require('./emailer'),
|
|
|
|
emailer = require('./emailer'),
|
|
|
|
db = require('./database'),
|
|
|
|
|
|
|
|
auth = require('./routes/authentication'),
|
|
|
|
|
|
|
|
meta = require('./meta'),
|
|
|
|
meta = require('./meta'),
|
|
|
|
user = require('./user'),
|
|
|
|
|
|
|
|
notifications = require('./notifications'),
|
|
|
|
|
|
|
|
logger = require('./logger'),
|
|
|
|
logger = require('./logger'),
|
|
|
|
plugins = require('./plugins'),
|
|
|
|
plugins = require('./plugins'),
|
|
|
|
middleware = require('./middleware'),
|
|
|
|
middleware = require('./middleware'),
|
|
|
@ -32,73 +31,51 @@ if(nconf.get('ssl')) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
(function (app) {
|
|
|
|
(function (app) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var port = nconf.get('PORT') || nconf.get('port');
|
|
|
|
var port = nconf.get('PORT') || nconf.get('port');
|
|
|
|
|
|
|
|
|
|
|
|
logger.init(app);
|
|
|
|
module.exports.init = function() {
|
|
|
|
emailer.registerApp(app);
|
|
|
|
emailer.registerApp(app);
|
|
|
|
|
|
|
|
|
|
|
|
if (cluster.isWorker && process.env.handle_jobs === 'true') {
|
|
|
|
|
|
|
|
notifications.init();
|
|
|
|
|
|
|
|
user.startJobs();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Preparation dependent on plugins
|
|
|
|
|
|
|
|
plugins.ready(function() {
|
|
|
|
|
|
|
|
async.parallel([
|
|
|
|
|
|
|
|
async.apply(!nconf.get('from-file') ? meta.js.minify : meta.js.getFromFile, app.enabled('minification')),
|
|
|
|
|
|
|
|
async.apply(!nconf.get('from-file') ? meta.css.minify : meta.css.getFromFile),
|
|
|
|
|
|
|
|
async.apply(meta.sounds.init)
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
// Preparation dependent on plugins
|
|
|
|
themesData: meta.themes.get,
|
|
|
|
plugins.ready(function() {
|
|
|
|
currentThemeId: function(next) {
|
|
|
|
async.parallel([
|
|
|
|
db.getObjectField('config', 'theme:id', next);
|
|
|
|
async.apply(!nconf.get('from-file') ? meta.js.minify : meta.js.getFromFile, app.enabled('minification')),
|
|
|
|
}
|
|
|
|
async.apply(!nconf.get('from-file') ? meta.css.minify : meta.css.getFromFile),
|
|
|
|
}, function(err, data) {
|
|
|
|
async.apply(meta.sounds.init)
|
|
|
|
middleware = middleware(app, data);
|
|
|
|
]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
middleware = middleware(app);
|
|
|
|
routes(app, middleware);
|
|
|
|
routes(app, middleware);
|
|
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
// Cache static files on production
|
|
|
|
winston.error('Errors were encountered while attempting to initialise NodeBB.');
|
|
|
|
if (global.env !== 'development') {
|
|
|
|
process.exit();
|
|
|
|
app.enable('cache');
|
|
|
|
} else {
|
|
|
|
app.enable('minification');
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
|
|
|
|
winston.info('Middlewares loaded.');
|
|
|
|
// Configure cache-buster timestamp
|
|
|
|
}
|
|
|
|
require('child_process').exec('git describe --tags', {
|
|
|
|
|
|
|
|
cwd: path.join(__dirname, '../')
|
|
|
|
|
|
|
|
}, function(err, stdOut) {
|
|
|
|
|
|
|
|
if (!err) {
|
|
|
|
|
|
|
|
meta.config['cache-buster'] = stdOut.trim();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
fs.stat(path.join(__dirname, '../package.json'), function(err, stats) {
|
|
|
|
|
|
|
|
meta.config['cache-buster'] = new Date(stats.mtime).getTime();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cache static files on production
|
|
|
|
if (port !== 80 && port !== 443 && nconf.get('use_port') === false) {
|
|
|
|
if (global.env !== 'development') {
|
|
|
|
winston.info('Enabling \'trust proxy\'');
|
|
|
|
app.enable('cache');
|
|
|
|
app.enable('trust proxy');
|
|
|
|
app.enable('minification');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Configure cache-buster timestamp
|
|
|
|
|
|
|
|
require('child_process').exec('git describe --tags', {
|
|
|
|
|
|
|
|
cwd: path.join(__dirname, '../')
|
|
|
|
|
|
|
|
}, function(err, stdOut) {
|
|
|
|
|
|
|
|
if (!err) {
|
|
|
|
|
|
|
|
meta.config['cache-buster'] = stdOut.trim();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
fs.stat(path.join(__dirname, '../package.json'), function(err, stats) {
|
|
|
|
|
|
|
|
meta.config['cache-buster'] = new Date(stats.mtime).getTime();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (port !== 80 && port !== 443 && nconf.get('use_port') === false) {
|
|
|
|
|
|
|
|
winston.info('Enabling \'trust proxy\'');
|
|
|
|
|
|
|
|
app.enable('trust proxy');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((port === 80 || port === 443) && process.env.NODE_ENV !== 'development') {
|
|
|
|
if ((port === 80 || port === 443) && process.env.NODE_ENV !== 'development') {
|
|
|
|
winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md');
|
|
|
|
winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
server.on('error', function(err) {
|
|
|
|
server.on('error', function(err) {
|
|
|
|
winston.error(err.stack);
|
|
|
|
winston.error(err.stack);
|
|
|
@ -123,6 +100,8 @@ if(nconf.get('ssl')) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.listen = function(callback) {
|
|
|
|
module.exports.listen = function(callback) {
|
|
|
|
|
|
|
|
logger.init(app);
|
|
|
|
|
|
|
|
|
|
|
|
var bind_address = ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? '0.0.0.0' : nconf.get('bind_address')) + ':' + port;
|
|
|
|
var bind_address = ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? '0.0.0.0' : nconf.get('bind_address')) + ':' + port;
|
|
|
|
if (cluster.isWorker) {
|
|
|
|
if (cluster.isWorker) {
|
|
|
|
port = 0;
|
|
|
|
port = 0;
|
|
|
|