server.js: rewritten to use Promises
This commit is contained in:
parent
a579dfc285
commit
4877ec319a
1 changed files with 31 additions and 47 deletions
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
|
||||
var log4js = require('log4js')
|
||||
, async = require('async')
|
||||
, NodeVersion = require('./utils/NodeVersion')
|
||||
;
|
||||
|
||||
|
@ -49,52 +48,37 @@ stats.gauge('memoryUsage', function() {
|
|||
return process.memoryUsage().rss;
|
||||
});
|
||||
|
||||
var settings
|
||||
, db
|
||||
, plugins
|
||||
, hooks;
|
||||
/*
|
||||
* no use of let or await here because it would cause startup
|
||||
* to fail completely on very early versions of NodeJS
|
||||
*/
|
||||
var npm = require("npm/lib/npm.js");
|
||||
|
||||
async.waterfall([
|
||||
// load npm
|
||||
function(callback) {
|
||||
npm.load({}, function(er) {
|
||||
callback(er);
|
||||
npm.load({}, function() {
|
||||
var settings = require('./utils/Settings');
|
||||
var db = require('./db/DB');
|
||||
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
||||
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
|
||||
hooks.plugins = plugins;
|
||||
|
||||
db.init()
|
||||
.then(plugins.update)
|
||||
.then(function() {
|
||||
console.info("Installed plugins: " + plugins.formatPluginsWithVersion());
|
||||
console.debug("Installed parts:\n" + plugins.formatParts());
|
||||
console.debug("Installed hooks:\n" + plugins.formatHooks());
|
||||
|
||||
// Call loadSettings hook
|
||||
hooks.aCallAll("loadSettings", { settings: settings });
|
||||
|
||||
// initalize the http server
|
||||
hooks.callAll("createServer", {});
|
||||
})
|
||||
.catch(function(e) {
|
||||
console.error("exception thrown: " + e.message);
|
||||
if (e.stack) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
},
|
||||
|
||||
// load everything
|
||||
function(callback) {
|
||||
settings = require('./utils/Settings');
|
||||
db = require('./db/DB');
|
||||
plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
||||
hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
|
||||
hooks.plugins = plugins;
|
||||
callback();
|
||||
},
|
||||
|
||||
// initalize the database
|
||||
function (callback) {
|
||||
db.init(callback);
|
||||
},
|
||||
|
||||
function(callback) {
|
||||
plugins.update(callback);
|
||||
},
|
||||
|
||||
function (callback) {
|
||||
console.info("Installed plugins: " + plugins.formatPluginsWithVersion());
|
||||
console.debug("Installed parts:\n" + plugins.formatParts());
|
||||
console.debug("Installed hooks:\n" + plugins.formatHooks());
|
||||
|
||||
// Call loadSettings hook
|
||||
hooks.aCallAll("loadSettings", { settings: settings });
|
||||
callback();
|
||||
},
|
||||
|
||||
// initalize the http server
|
||||
function (callback) {
|
||||
hooks.callAll("createServer", {});
|
||||
callback(null);
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue