mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	closes #2390
This commit is contained in:
		
							
								
								
									
										18
									
								
								app.js
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								app.js
									
									
									
									
									
								
							| @@ -25,6 +25,7 @@ nconf.argv().env(); | ||||
|  | ||||
| var fs = require('fs'), | ||||
| 	os = require('os'), | ||||
| 	async = require('async'), | ||||
| 	semver = require('semver'), | ||||
| 	winston = require('winston'), | ||||
| 	path = require('path'), | ||||
| @@ -141,14 +142,21 @@ function start() { | ||||
|  | ||||
| 					nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path')); | ||||
|  | ||||
| 					plugins.ready(function() { | ||||
| 						webserver.init(function() { | ||||
| 							webserver.listen(function() { | ||||
| 					async.waterfall([ | ||||
| 						async.apply(plugins.ready), | ||||
| 						async.apply(webserver.init), | ||||
| 						async.apply(webserver.listen) | ||||
| 					], function(err) { | ||||
| 						if (err) { | ||||
| 							winston.error(err.stack); | ||||
| 							process.exit(); | ||||
| 						} | ||||
|  | ||||
| 						if (process.send) { | ||||
| 							process.send({ | ||||
| 								action: 'ready' | ||||
| 							}); | ||||
| 							}); | ||||
| 						}); | ||||
| 						} | ||||
| 					}); | ||||
|  | ||||
| 					process.on('SIGTERM', shutdown); | ||||
|   | ||||
| @@ -17,12 +17,10 @@ var mkdirp = require('mkdirp'), | ||||
|  | ||||
| Templates.compile = function(callback) { | ||||
| 	if (cluster.isWorker && process.env.cluster_setup !== 'true') { | ||||
| 		return setTimeout(function() { | ||||
| 		emitter.emit('templates:compiled'); | ||||
| 		if (callback) { | ||||
| 			callback(); | ||||
| 		} | ||||
| 		}, 1000); | ||||
| 	} | ||||
|  | ||||
| 	var coreTemplatesPath = nconf.get('core_templates_path'), | ||||
|   | ||||
| @@ -108,7 +108,6 @@ module.exports = function(app, data) { | ||||
| 	auth.initialize(app, middleware); | ||||
|  | ||||
| 	routeCurrentTheme(app, data.currentThemeId, data.themesData); | ||||
| 	meta.templates.compile(); | ||||
|  | ||||
| 	return middleware; | ||||
| }; | ||||
|   | ||||
| @@ -100,9 +100,7 @@ if(nconf.get('ssl')) { | ||||
| 		winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md'); | ||||
| 	} | ||||
|  | ||||
| 	module.exports.server = server; | ||||
| 	module.exports.init = function(callback) { | ||||
| 		server.on("error", function(err){ | ||||
| 	server.on('error', function(err) { | ||||
| 		winston.error(err.stack); | ||||
| 		console.log(err.stack); | ||||
| 		if (err.code === 'EADDRINUSE') { | ||||
| @@ -117,24 +115,28 @@ if(nconf.get('ssl')) { | ||||
| 		} | ||||
| 	}); | ||||
|  | ||||
| 	module.exports.server = server; | ||||
|  | ||||
| 	module.exports.init = function(callback) { | ||||
|  | ||||
| 		emitter.all(['templates:compiled', 'meta:js.compiled', 'meta:css.compiled'], function() { | ||||
| 			winston.info('NodeBB Ready'); | ||||
| 			emitter.emit('nodebb:ready'); | ||||
| 			emitter.removeAllListeners('templates:compiled').removeAllListeners('meta:js.compiled').removeAllListeners('meta:css.compiled'); | ||||
| 		}); | ||||
|  | ||||
| 		if (process.send) { | ||||
| 			callback(); | ||||
| 		} else { | ||||
| 			module.exports.listen(); | ||||
| 		} | ||||
| 		meta.templates.compile(callback); | ||||
| 	}; | ||||
|  | ||||
| 	module.exports.listen = function(callback) { | ||||
| 		var	bind_address = ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? '0.0.0.0' : nconf.get('bind_address')) + ':' + port; | ||||
| 		winston.info('NodeBB attempting to listen on: ' + bind_address); | ||||
|  | ||||
| 		server.listen(port, nconf.get('bind_address'), function() { | ||||
| 		server.listen(port, nconf.get('bind_address'), function(err) { | ||||
| 			if (err) { | ||||
| 				return callback(err); | ||||
| 			} | ||||
|  | ||||
| 			winston.info('NodeBB is now listening on: ' + bind_address); | ||||
| 			if (process.send) { | ||||
| 				process.send({ | ||||
| @@ -144,9 +146,7 @@ if(nconf.get('ssl')) { | ||||
| 				}); | ||||
| 			} | ||||
|  | ||||
| 			if (typeof callback === 'function') { | ||||
| 			callback(); | ||||
| 			} | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user