This repository was archived by the owner on Feb 6, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +66
-37
lines changed Expand file tree Collapse file tree 4 files changed +66
-37
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ parserOptions:
88 sourceType : module
99
1010extends : ' eslint:recommended'
11-
11+ parser : babel-eslint
1212rules :
1313 no-var : 2
1414 key-spacing : 2
Original file line number Diff line number Diff line change 1+ import cors from 'cors' ;
2+ import helmet from 'helmet' ;
3+ import morgan from 'morgan' ;
4+ import express from 'express' ;
5+
6+ import pkg from '../package' ;
7+ import routes from './routes' ;
8+ import logger from './utils/logger' ;
9+ import bodyParser from 'body-parser' ;
10+ import compression from 'compression' ;
11+ import * as config from './config/config' ;
12+ import * as errorHandler from './middlewares/errorHandler' ;
13+
14+ const app = express ( ) ;
15+
16+ app . set ( 'port' , config . get ( ) . restApi . port ) ;
17+
18+ app . locals . title = pkg . name ;
19+ app . locals . version = pkg . version ;
20+
21+ app . use ( cors ( ) ) ;
22+ app . use ( helmet ( ) ) ;
23+ app . use ( compression ( ) ) ;
24+ app . use ( morgan ( 'dev' ) ) ;
25+ app . use ( bodyParser . json ( ) ) ;
26+
27+ // API Routes
28+ app . use ( '/api' , routes ) ;
29+
30+ // Error Middlewares
31+ app . use ( errorHandler . genericErrorHandler ) ;
32+ app . use ( errorHandler . notFoundError ) ;
33+
34+ app . listen ( app . get ( 'port' ) , ( ) => {
35+ logger ( ) . info ( `Server listening is on port ${ app . get ( 'port' ) } ` ) ;
36+ } ) ;
37+
38+ export default app ;
Original file line number Diff line number Diff line change 11import 'babel-polyfill' ;
2- import cors from 'cors' ;
3- import helmet from 'helmet' ;
4- import morgan from 'morgan' ;
5- import express from 'express' ;
2+ import init from './init' ;
63
7- import pkg from '../package' ;
8- import routes from './routes' ;
9- import logger from './utils/logger' ;
10- import bodyParser from 'body-parser' ;
11- import compression from 'compression' ;
12- import * as errorHandler from './middlewares/errorHandler' ;
13-
14- const app = express ( ) ;
15-
16- const PORT = process . env . PORT || '3000' ;
17-
18- app . set ( 'port' , PORT ) ;
19-
20- app . locals . title = pkg . name ;
21- app . locals . version = pkg . version ;
22-
23- app . use ( cors ( ) ) ;
24- app . use ( helmet ( ) ) ;
25- app . use ( compression ( ) ) ;
26- app . use ( morgan ( 'dev' ) ) ;
27- app . use ( bodyParser . json ( ) ) ;
28-
29- // API Routes
30- app . use ( '/api' , routes ) ;
31-
32- // Error Middlewares
33- app . use ( errorHandler . genericErrorHandler ) ;
34- app . use ( errorHandler . notFoundError ) ;
35-
36- app . listen ( app . get ( 'port' ) , ( ) => {
37- logger ( ) . info ( `Server listening is on port ${ app . get ( 'port' ) } ` ) ;
4+ init ( ( ) => {
5+ import ( './app' ) ;
386} ) ;
397
40- export default app ;
Original file line number Diff line number Diff line change 1+ import path from 'path' ;
2+ import pkg from '../package' ;
3+
4+ /**
5+ * Initialize the monitor and start monitoring configured services.
6+ */
7+ export default async function init ( callback ) {
8+ process . stdout . write ( `Starting ${ pkg . name } ${ pkg . version } \n` ) ;
9+
10+ try {
11+ const { resolve, DEFAULT_FILENAME } = await import ( './config/config' ) ;
12+
13+ // Config file for chill could be added using environment variables too.
14+ const configFile = process . env . CHILL_CONFIG || path . resolve ( DEFAULT_FILENAME ) ;
15+ const config = resolve ( configFile ) ;
16+
17+ callback ( config ) ;
18+
19+ return ;
20+ // Start the app
21+ } catch ( err ) {
22+ process . stderr . write ( 'An error occurred: \n' + err ) ;
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments