-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (31 loc) · 1.14 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
'use strict';
/** * Dependencies */
let spcommon = require( 'sp-common'),
config = require('./server/config/config');
/** * Initialize Utils, Libraries */
spcommon.init( config );
let l = spcommon.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 *() {
var app = module.exports = koa();
app.init = co.wrap(function *() {
koaConfig(app);
l.info("Initiating web service at: ", config.app.port);
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);
});