mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
cluster socket.io fixes
close proxy server on loader.stop changed handles to object
This commit is contained in:
103
src/webserver.js
103
src/webserver.js
@@ -1,3 +1,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var path = require('path'),
|
||||
fs = require('fs'),
|
||||
nconf = require('nconf'),
|
||||
@@ -9,11 +12,7 @@ var path = require('path'),
|
||||
cluster = require('cluster'),
|
||||
|
||||
emailer = require('./emailer'),
|
||||
db = require('./database'),
|
||||
auth = require('./routes/authentication'),
|
||||
meta = require('./meta'),
|
||||
user = require('./user'),
|
||||
notifications = require('./notifications'),
|
||||
logger = require('./logger'),
|
||||
plugins = require('./plugins'),
|
||||
middleware = require('./middleware'),
|
||||
@@ -32,73 +31,51 @@ if(nconf.get('ssl')) {
|
||||
}
|
||||
|
||||
(function (app) {
|
||||
"use strict";
|
||||
|
||||
var port = nconf.get('PORT') || nconf.get('port');
|
||||
|
||||
logger.init(app);
|
||||
emailer.registerApp(app);
|
||||
module.exports.init = function() {
|
||||
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)
|
||||
]);
|
||||
});
|
||||
|
||||
// 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({
|
||||
themesData: meta.themes.get,
|
||||
currentThemeId: function(next) {
|
||||
db.getObjectField('config', 'theme:id', next);
|
||||
}
|
||||
}, function(err, data) {
|
||||
middleware = middleware(app, data);
|
||||
middleware = middleware(app);
|
||||
routes(app, middleware);
|
||||
|
||||
if (err) {
|
||||
winston.error('Errors were encountered while attempting to initialise NodeBB.');
|
||||
process.exit();
|
||||
} else {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
winston.info('Middlewares loaded.');
|
||||
}
|
||||
// Cache static files on production
|
||||
if (global.env !== 'development') {
|
||||
app.enable('cache');
|
||||
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();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Cache static files on production
|
||||
if (global.env !== 'development') {
|
||||
app.enable('cache');
|
||||
app.enable('minification');
|
||||
if (port !== 80 && port !== 443 && nconf.get('use_port') === false) {
|
||||
winston.info('Enabling \'trust proxy\'');
|
||||
app.enable('trust proxy');
|
||||
}
|
||||
|
||||
// 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') {
|
||||
winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md');
|
||||
}
|
||||
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');
|
||||
}
|
||||
};
|
||||
|
||||
server.on('error', function(err) {
|
||||
winston.error(err.stack);
|
||||
@@ -123,6 +100,8 @@ if(nconf.get('ssl')) {
|
||||
});
|
||||
|
||||
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;
|
||||
if (cluster.isWorker) {
|
||||
port = 0;
|
||||
|
||||
Reference in New Issue
Block a user