import * as express from 'express' ; import * as partialResponse from 'express-partial-response' ; import * as path from 'path' ; import { secureApp , configLogging , configMetrics , configHealthChecks , addCompression } from './config' ; import { IOCContainer } from './config/ioc_config' ; import { InversifyExpressServer } from 'inversify-express-utils' ; const responseTime = require ( 'response-time' ) ; /**
 * Node Express Server setup and configuration
 */ export default class ExpressServer { public server : InversifyExpressServer ; constructor ( exApp ) { let root ; root = process . env . NODE_ENV === 'development' ? path . normalize ( __dirname + '/../..' ) : path . normalize ( '.' ) ; const container = IOCContainer . getInstance ( ) . getContainer ( ) ; this . server = new InversifyExpressServer ( container , undefined , { rootPath : '/api/v1' } , exApp ) ; this . server . setConfig ( app => { secureApp ( app ) ; app . use ( ( req , res , next ) => { res . header ( 'Access-Control-Allow-Origin' , '*' ) ; res . header ( 'Access-Control-Allow-Methods' , 'GET, PUT, POST, DELETE' ) ; res . header ( 'Access-Control-Allow-Headers' , 'Origin, X-Requested-With, Content-Type, Accept' ) ; next ( ) ; } ) ; app . use ( express . static ( `${ root }/public` ) ) ; app . use ( responseTime ( { suffix : false } ) ) ; app . use ( partialResponse ( ) ) ; configLogging ( app ) ; configMetrics ( app ) ; configHealthChecks ( app ) ; addCompression ( app ) ; } ) ; } public getServer = ( ) : InversifyExpressServer => { return this . server ; } ; }