server.js: rewritten to use Promises

pull/3559/head
Ray Bellis 2019-01-18 16:10:25 +00:00
parent a579dfc285
commit 4877ec319a
1 changed files with 31 additions and 47 deletions

View File

@ -22,7 +22,6 @@
*/ */
var log4js = require('log4js') var log4js = require('log4js')
, async = require('async')
, NodeVersion = require('./utils/NodeVersion') , NodeVersion = require('./utils/NodeVersion')
; ;
@ -49,52 +48,37 @@ stats.gauge('memoryUsage', function() {
return process.memoryUsage().rss; return process.memoryUsage().rss;
}); });
var settings /*
, db * no use of let or await here because it would cause startup
, plugins * to fail completely on very early versions of NodeJS
, hooks; */
var npm = require("npm/lib/npm.js"); var npm = require("npm/lib/npm.js");
async.waterfall([ npm.load({}, function() {
// load npm var settings = require('./utils/Settings');
function(callback) { var db = require('./db/DB');
npm.load({}, function(er) { var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
callback(er); var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
});
},
// 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; hooks.plugins = plugins;
callback();
},
// initalize the database db.init()
function (callback) { .then(plugins.update)
db.init(callback); .then(function() {
},
function(callback) {
plugins.update(callback);
},
function (callback) {
console.info("Installed plugins: " + plugins.formatPluginsWithVersion()); console.info("Installed plugins: " + plugins.formatPluginsWithVersion());
console.debug("Installed parts:\n" + plugins.formatParts()); console.debug("Installed parts:\n" + plugins.formatParts());
console.debug("Installed hooks:\n" + plugins.formatHooks()); console.debug("Installed hooks:\n" + plugins.formatHooks());
// Call loadSettings hook // Call loadSettings hook
hooks.aCallAll("loadSettings", { settings: settings }); hooks.aCallAll("loadSettings", { settings: settings });
callback();
},
// initalize the http server // initalize the http server
function (callback) {
hooks.callAll("createServer", {}); hooks.callAll("createServer", {});
callback(null); })
.catch(function(e) {
console.error("exception thrown: " + e.message);
if (e.stack) {
console.log(e.stack);
} }
]); process.exit(1);
});
});