-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
40 lines (32 loc) · 1.08 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Provider } from './http/provider';
import { RouteHandler } from './http/routeHandler';
import swaggerUi from 'swagger-ui-express';
const options = {
swaggerUrl: `/api-doc`
};
export function app(value: any) {
return function (constructor: any) {
const {controllers, application} = value;
if (controllers && controllers.length > 0) {
controllers.forEach((controller: any) => {
Provider.getDefaultProvider().register(Symbol(controller.name), controller);
});
}
const express = application.provider;
constructor.prototype.express = express;
const middlewares = application.middlewares;
const setters = application.setters;
for (const key in setters) {
express.set(key, setters[key]);
}
if (middlewares && middlewares.length > 0) {
middlewares.forEach((middleware: any) => {
express.use(middleware);
});
}
if (process.env['NODE_ENV'] !== 'production') {
express.use('/swagger', swaggerUi.serve, swaggerUi.setup(undefined, options));
}
RouteHandler.RegisterToExpress(express);
};
}