-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
34 lines (27 loc) · 954 Bytes
/
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
import express, { Request, Response } from 'express';
import { BaseController } from './BaseController';
import { ChatController } from './controllers'
export class App {
private _port: number = 80;
private _server: any;
constructor() {}
public Init() {
this._server = express();
this._server.listen(this._port);
this.setupFiles();
this.setupRoute("/api/chat", new ChatController());
}
private setupFiles() {
this._server.get('/', (req: Request, res: Response) => {
res.sendFile(__dirname + "/web/home.html");
});
this._server.get('/main.js', (req: Request, res: Response) => {
res.sendFile(__dirname + "/web/main.js");
});
}
private setupRoute(path: string, handler: BaseController) {
this._server.get(path, async (req: Request, res: Response) => {
await handler.process(req, res);
});
}
}