server.js: rewritten to use Promises

This commit is contained in:
Ray Bellis 2019-01-18 16:10:25 +00:00
parent a579dfc285
commit 4877ec319a

View file

@ -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);
});
},
// 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");
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;
callback();
},
// initalize the database
function (callback) {
db.init(callback);
},
function(callback) {
plugins.update(callback);
},
function (callback) {
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 });
callback();
},
// initalize the http server
function (callback) {
hooks.callAll("createServer", {});
callback(null);
})
.catch(function(e) {
console.error("exception thrown: " + e.message);
if (e.stack) {
console.log(e.stack);
}
]);
process.exit(1);
});
});