/
Server.ts
52 lines (47 loc) · 1.24 KB
/
Server.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
41
42
43
44
45
46
47
48
49
50
51
52
import {GlobalAcceptMimesMiddleware, ServerLoader, ServerSettings} from "@tsed/common";
import "@tsed/swagger";
import {$log} from "ts-log-debug";
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const compress = require("compression");
const methodOverride = require("method-override");
const rootDir = __dirname;
@ServerSettings({
rootDir,
acceptMimes: ["application/json"],
logger: {
debug: false,
logRequest: true,
requestFields: ["reqId", "method", "url", "headers", "query", "params", "duration"]
},
swagger: {
path: "/api-docs"
},
calendar: {
token: true
}
})
export class Server extends ServerLoader {
/**
* This method let you configure the middleware required by your application to works.
* @returns {Server}
*/
$onMountingMiddlewares(): void | Promise<any> {
this
.use(GlobalAcceptMimesMiddleware)
.use(cookieParser())
.use(compress({}))
.use(methodOverride())
.use(bodyParser.json())
.use(bodyParser.urlencoded({
extended: true
}));
return null;
}
$onReady() {
$log.debug("Server initialized");
}
$onServerInitError(error): any {
$log.error("Server encounter an error =>", error);
}
}