forked from linagora/openpaas-esn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (35 loc) · 1015 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
var async = require('async');
var moduleManager = require('./backend/module-manager');
var core = require('./backend/core');
var logger = core.logger;
var config = core.config('default');
var modules = config.modules;
moduleManager.setupServerEnvironment();
function fireESNState(state) {
return function fireESN(callback) {
moduleManager.manager.fire(state, modules).then(function() {
callback(null);
}, function(err) {
callback(err);
});
};
}
function initCore(callback) {
core.init(function(err) {
if (!err) {
logger.info('OpenPaaS Core bootstraped, configured in %s mode', process.env.NODE_ENV);
}
callback(err);
});
}
async.series([core.templates.inject, fireESNState('lib'), initCore, fireESNState('start')], function(err) {
if (err) {
logger.error('Fatal error:', err);
if (err.stack) {
logger.error(err.stack);
}
process.exit(1);
}
logger.info('OpenPaas ESN is now started on node %s', process.version);
});