-
Notifications
You must be signed in to change notification settings - Fork 3
/
baboon-backend.js
57 lines (42 loc) · 1.42 KB
/
baboon-backend.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
#!/usr/bin/env node
/*eslint new-cap:0 */
'use strict';
// Environment default settings
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
process.env.PORT = process.env.PORT || 3000;
process.env.HOST = process.env.HOST || '127.0.0.1';
var baboon = require('./lib');
var debug = require('debug')('baboon');
var options = {};
// Add errors
options.errors = baboon.lxErrors;
debug('Load configuration');
// Config
var config = new baboon.LxConfig(__dirname);
options.config = config;
var events = require('events');
var eventEmitter = new events.EventEmitter();
debug('Start project application config');
// load application Modules
baboon.LxLoader(options, function (err, options) {
// check errors and start server
if (!err) {
debug('application modules loaded');
// start server
var server = options.server;
server.listen(options.config.PORT, options.config.HOST, function () {
debug('Express server listening on port ' + server.address().port);
// Events for regression tests
eventEmitter.emit('server_started');
eventEmitter.on('server_stop', function(){
server._connections = 0;
server.close(function () {
eventEmitter.emit('server_stopped');
});
});
});
} else {
throw new Error(err);
}
});
exports.eventEmitter = eventEmitter;