import express, { Express, Router } from "express"; import { Service } from "typedi"; import ServerInterface, { IConfig } from "./ServerInterface"; @Service() export default class ExpressServer implements ServerInterface { public router: Express = express(); private subRouter: Router = express.Router(); public getRouter(): Router { return this.subRouter; } protected getMainRouter(): Express { return this.router; } public init(config: IConfig) { this.router.use(...config.middlwares); this.router.use(config.rootUrl, this.subRouter); if (config.errorHandler) this.router.use(config.errorHandler); return this; } public listen() { return this.router.listen(3001, () => { console.table( [ { "Entry label": "le coffre API", Port: 3001, "Root url": "/api", }, ], ["Entry label", "Port", "Root url"], ); }); } }