import { Application } from 'express' ; import express from 'express' ; import * as bodyParser from 'body-parser' ; import { MicroframeworkLoader , MicroframeworkSettings } from 'microframework-w3tec' ; import { useExpressServer } from 'routing-controllers' ; import { authorizationChecker } from '../auth/authorizationChecker' ; import { currentUserChecker } from '../auth/currentUserChecker' ; import { env } from '../env' ; export const expressLoader = ( settings ) => { if ( settings ) { const connection = settings . getData ( 'connection' ) ; /**
         * We create a new express server instance.
         * We could have also use useExpressServer here to attach controllers to an existing express instance.
         */ const app = express ( ) ; app . use ( bodyParser . urlencoded ( { extended : true } ) ) ; app . use ( bodyParser . json ( { limit : '50mb' } ) ) ; const expressApp = useExpressServer ( app , { cors : true , classTransformer : true , routePrefix : env . app . routePrefix , defaultErrorHandler : false , /**
             * We can add options about how routing-controllers should configure itself.
             * Here we specify what controllers should be registered in our express server.
             */ controllers : env . app . dirs . controllers , middlewares : env . app . dirs . middlewares , interceptors : env . app . dirs . interceptors , /**
             * Authorization features
             */ authorizationChecker : authorizationChecker ( connection ) , currentUserChecker : currentUserChecker ( connection ) , } ) ; if ( ! env . isTest ) { const server = expressApp . listen ( env . app . port ) ; settings . setData ( 'express_server' , server ) ; } settings . setData ( 'express_app' , expressApp ) ; } } ;