lecoffre-back/src/common/system/ExpressServerTest.ts
Arnaud D. Natali 3dc043e6c4
Feature/services test (#17)
controllers, repositories, services and associated tests for:

Deed types, Deed, Document types, Users and Customers

---------

Co-authored-by: Vincent Alamelle <vincent.alamelle@smart-chain.fr>
Co-authored-by: OxSaitama <arnaud.daubernatali@smart-chain.fr>
2023-04-06 18:43:13 +02:00

40 lines
887 B
TypeScript

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"],
);
});
}
}