import 'reflect-metadata' ; import express , { Request , NextFunction , Response } from 'express' ; import { Container } from 'typedi' ; import './utils/env' ; import { useContainer , useExpressServer } from 'routing-controllers' ; import { routingControllerOptions } from './utils/routingConfig' ; import swaggerUi from 'swagger-ui-express' ; useContainer ( Container ) ; const app = express ( ) ; console . log ( `Current NODE_ENV is ${ process . env . NODE_ENV }` ) ; app . use ( express . static ( __dirname + '/view' ) ) ; useExpressServer ( app , routingControllerOptions ) ; export function runServer ( host , port ) { return new Promise ( ( resolve , reject ) => { app . listen ( port , host , ( err ) => { if ( err ) { reject ( err ) ; } resolve ( ) ; } ) ; } ) ; } import { spec } from './utils/swagger' ; app . use ( swaggerUi . serve ) ; app . get ( '/swagger' , swaggerUi . setup ( spec ) ) ; app . get ( '/' , ( _ , res ) => { res . sendFile ( './view/index.html' ) ; } ) ; app . get ( '/swagger.json' , ( _ , res ) => { res . json ( spec ) ; } ) ; app . use ( ( err , _req , res , _next ) => { res . end ( `{ result: false, error: ${ err } }` ) ; } ) ; export { app } ;