forked from RackHD/on-http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (73 loc) · 2.65 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2015, EMC, Inc.
"use strict";
var _ = require('lodash'), /* jshint ignore: line */
_di = require('di'),
onCore = require('on-core'),
onTasks = require('on-tasks');
var self = module.exports = {
injector: null,
onHttpContextFactory: onHttpContextFactory
};
function onHttpContextFactory(di, directory) {
di = di || _di;
var core = onCore(di, directory),
helper = core.helper;
return {
helper: helper,
initialize: function () {
var injector = new di.Injector(_.flattenDeep([
core.injectables,
this.prerequisiteInjectables,
this.injectables
]));
this.app = injector.get('app'),
this.logger = injector.get('Logger').initialize('Http.Server');
self.injector = injector;
return this;
},
injectables: _.flattenDeep([
helper.requireGlob(__dirname + '/lib/api/login/*.js'),
helper.requireGlob(__dirname + '/lib/api/view/*.js'),
helper.requireGlob(__dirname + '/lib/services/**/*.js'),
helper.requireGlob(__dirname + '/lib/serializables/**/*.js'),
require('./app'),
helper.requireWrapper('rimraf', 'rimraf', undefined, __dirname),
helper.requireWrapper('os-tmpdir', 'osTmpdir', undefined, __dirname),
helper.requireWrapper('fs-extra', 'fs', undefined, __dirname),
helper.requireWrapper('os', 'os', undefined, __dirname),
helper.requireWrapper('node-cache', 'node-cache', undefined, __dirname)
]),
prerequisiteInjectables: _.flattenDeep([
core.workflowInjectables,
onTasks.injectables,
helper.requireWrapper('swagger-express-mw', 'swagger', undefined, __dirname)
])
};
}
if (require.main === module) { run(); }
function run() {
var onHttpContext = onHttpContextFactory().initialize(),
app = onHttpContext.app,
logger = onHttpContext.logger;
app.start()
.then(function () {
logger.info('Server Started.');
})
.catch(function(error) {
logger.critical('Server Startup Error.', { error: error });
process.nextTick(function() {
process.exit(1);
});
});
process.on('SIGINT', function() {
app.stop()
.catch(function(error) {
logger.critical('Server Shutdown Error.', { error: error });
})
.finally(function() {
process.nextTick(function() {
process.exit(1);
});
});
});
}