declare type ConfigureCallback = (app: express.Express) => void; import * as bodyParser from "body-parser"; import * as cors from "cors"; import * as express from "express"; import * as requireAll from "require-all"; import {Config} from "./config/config"; import {IConfig} from "./types/IConfig"; export class App { static expressApp: express.Express = express(); static config: Config = new Config(); constructor(config: IConfig = {}) { App.config = Object.assign(App.config, config); this.SetConfig(); } public Init(): express.Express { requireAll({ dirname : process.cwd() + `/${App.config.compiledPath}/controllers`, filter : /.+\.js$/, recursive : true }); return App.expressApp; } private SetConfig() { App.expressApp.set("baseRoute", App.config.baseRoute); App.expressApp.use(bodyParser.urlencoded({ extended: true })); if(App.config.bodyParserEnabled) App.expressApp.use(bodyParser.json()); if(App.config.corsEnabled) App.expressApp.use(cors({ exposedHeaders: App.config.exposedHeaders })); if(App.config.serverRenderingEnabled){ App.expressApp.use(express.static('./views')) App.expressApp.set('views', './views') App.expressApp.set('view engine', App.config.serverRenderingEngine) } } public Configure(callback: ConfigureCallback): void { callback(App.expressApp); } public get express(): express.Express { return App.expressApp; } }