added emitter class; express.listen only after background tasks complete; closes #1227

v1.18.x
psychobunny 11 years ago
parent 16f1db4f5d
commit 941c3b2d7e

@ -0,0 +1,4 @@
var events = require('events'),
eventEmitter = new events.EventEmitter();
module.exports = eventEmitter;

@ -7,6 +7,8 @@ var templates = require('./../../public/src/templates'),
plugins = require('./../plugins'), plugins = require('./../plugins'),
db = require('./../database'), db = require('./../database'),
auth = require('./../routes/authentication'), auth = require('./../routes/authentication'),
emitter = require('./../emitter'),
async = require('async'), async = require('async'),
path = require('path'), path = require('path'),
fs = require('fs'), fs = require('fs'),
@ -119,6 +121,7 @@ function compileTemplates(pluginTemplates) {
if (err) { if (err) {
winston.error(err); winston.error(err);
} else { } else {
emitter.emit('templates:compiled');
winston.info('[themes] Successfully compiled templates.'); winston.info('[themes] Successfully compiled templates.');
} }
}); });

@ -14,7 +14,8 @@ var path = require('path'),
meta = require('./meta'), meta = require('./meta'),
logger = require('./logger'), logger = require('./logger'),
middleware = require('./middleware'), middleware = require('./middleware'),
routes = require('./routes'); routes = require('./routes'),
emitter = require('./emitter');
if(nconf.get('ssl')) { if(nconf.get('ssl')) {
server = require('https').createServer({ server = require('https').createServer({
@ -92,9 +93,11 @@ if(nconf.get('ssl')) {
} }
}); });
winston.info('NodeBB attempting to listen on: ' + ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? '0.0.0.0' : nconf.get('bind_address')) + ':' + port); emitter.on('templates:compiled', function() {
server.listen(port, nconf.get('bind_address'), function(){ winston.info('NodeBB attempting to listen on: ' + ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? '0.0.0.0' : nconf.get('bind_address')) + ':' + port);
winston.info('NodeBB Ready'); server.listen(port, nconf.get('bind_address'), function(){
winston.info('NodeBB Ready');
});
}); });
}; };

Loading…
Cancel
Save