forked from sooluh/kodepos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
51 lines (40 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
41
42
43
44
45
46
47
48
49
50
51
import Routes from "./src/routes";
import compress from "fastify-compress";
import Fastify from "fastify";
import middie from "middie";
import { parse } from "qs";
import cors from "cors";
class App extends Routes {
private port: number = 3000;
private server: any;
constructor() {
super();
this.port = parseInt(process.env.PORT || "") || this.port;
this.server = Fastify({
ignoreTrailingSlash: true,
caseSensitive: false,
querystringParser: q => parse(q)
});
}
private async middleware(): Promise<void> {
// express compatibility layer
this.server.use(cors());
// fastify register
await this.server.register(compress);
}
public async start(): Promise<void> {
try {
await this.server.register(middie);
await this.middleware();
this.server.setNotFoundHandler(this.override);
this.server.setErrorHandler(this.error);
this.routes(this.server);
let address = await this.server.listen(this.port);
console.info("Listen to requests on " + address);
} catch (error) {
this.server.log.error(error);
process.exit(1);
}
}
}
new App().start();