11import express from 'express' ;
22import logger from 'morgan' ;
33import bodyParser from 'body-parser' ;
4+ import cookieParser from 'cookie-parser' ;
45import compress from 'compression' ;
56import methodOverride from 'method-override' ;
67import cors from 'cors' ;
78import httpStatus from 'http-status' ;
89import routes from '../server/routes' ;
10+ import config from './env' ;
911import * as utilityService from '../server/services/utility' ;
1012
1113const app = express ( ) ;
1214
1315app . use ( logger ( 'dev' ) ) ;
1416
15- // parses body params and attaches them to req.body
17+ // parse body params and attache them to req.body
1618app . use ( bodyParser . json ( ) ) ;
1719app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
1820
21+ app . use ( cookieParser ( ) ) ;
1922app . use ( compress ( ) ) ;
2023app . use ( methodOverride ( ) ) ;
2124
22- // Enable CORS - Cross Origin Resource Sharing
25+ // enable CORS - Cross Origin Resource Sharing
2326app . use ( cors ( ) ) ;
2427
2528// mount all routes on /api path
@@ -37,11 +40,11 @@ app.use((req, res, next) => {
3740 return next ( err ) ;
3841} ) ;
3942
40- // error handler
43+ // error handler, send stacktrace only during development
4144app . use ( ( err , req , res , next ) => // eslint-disable-line no-unused-vars
4245 res . status ( err . status ) . json ( {
4346 message : err . isPublic ? err . message : httpStatus [ err . status ] ,
44- error : process . env . NODE_ENV === 'development' ? err : { }
47+ error : config . NODE_ENV === 'development' ? err : { }
4548 } )
4649) ;
4750
0 commit comments