Last active
May 29, 2019 15:01
-
-
Save seanpmaxwell/fb58c95f0adc055403445e03f4f499fb to your computer and use it in GitHub Desktop.
ExpressTypeScript/ExampleServer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as bodyParser from 'body-parser'; | |
| import * as controllers from './controllers'; | |
| import { Server } from '@overnightjs/core'; | |
| import { Logger } from '@overnightjs/logger'; | |
| class ExampleServer extends Server { | |
| private readonly SERVER_STARTED = 'Example server started on port: '; | |
| constructor() { | |
| super(true); | |
| this.app.use(bodyParser.json()); | |
| this.app.use(bodyParser.urlencoded({extended: true})); | |
| this.setupControllers(); | |
| } | |
| private setupControllers(): void { | |
| const ctlrInstances = []; | |
| for (const name in controllers) { | |
| if (controllers.hasOwnProperty(name)) { | |
| const controller = (controllers as any)[name]; | |
| ctlrInstances.push(new controller()); | |
| } | |
| } | |
| super.addControllers(ctlrInstances); | |
| } | |
| public start(port: number): void { | |
| this.app.get('*', (req, res) => { | |
| res.send(this.SERVER_STARTED + port); | |
| }); | |
| this.app.listen(port, () => { | |
| Logger.Imp(this.SERVER_STARTED + port); | |
| }); | |
| } | |
| } | |
| export default ExampleServer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment