-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
45 lines (34 loc) · 996 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
35
36
37
38
39
40
41
42
43
44
45
import express, { Application } from 'express'
import morgan from 'morgan'
import apiRouter from "./routes/api";
import bodyParser from 'body-parser';
require('dotenv').config();
export class App {
app: Application;
constructor(
private port?: number | string
) {
this.app = express();
this.settings();
// this.middleware();
// this.routes();
this.apiRoutes();
}
private settings() {
this.app.set('port', this.port || process.env.PORT || 3000);
}
private middleware() {
this.app.use(morgan('dev'));
this.app.use(express.json());
this.app.use(bodyParser.json());
}
private apiRoutes(){
this.app.use('/api',apiRouter);
this.app.use(express.json());
this.app.use(bodyParser.json());
}
async listen(): Promise<void> {
await this.app.listen(this.app.get('port'));
console.log('Server on port', this.app.get('port'));
}
}