-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (37 loc) · 1.35 KB
/
app.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
'use strict';
/**
* Entry point for league mgr
* Initiates database connection and starts listening for requests on configured port.
*/
/** * Dependencies */
let flcommon = require( 'fl-common'),
config = require('./server/config/config');
/** * Initialize Utils, Libraries and Mongoose ODM */
flcommon.init( config );
let l = flcommon.logger.child( {'module': __filename.substring(__dirname.length+1, __filename.length-3)} ),
co = require('co');
process.on( 'uncaughtException', ( err ) => { l.error( err, "uncaught Exception" ); });
process.on( 'uncaughtRejection', ( err ) => { l.error( err, "uncaught Rejection" ); });
var koa = require('koa'),
koaConfig = require('./server/config/koa');
/** * create server, configure the router middleware */
co(function *() {
yield flcommon.initDB();
var app = module.exports = koa();
app.init = co.wrap(function *() {
l.info("Initiating app");
koaConfig(app);
l.info("Initiating web service at: ", config.app.port);
app.server = app.listen(config.app.port);
});
/** * auto init if this app is not being initialized by another module (i.e. using require('./app').init();) */
if (!module.parent) {
l.info("Configuring web service");
return app.init();
}
}).then(() => {
l.info('Web service started');
}).catch(err => {
l.error( err, 'Error in initiating web service: ', err.message);
process.exit(1);
});