-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
52 lines (42 loc) · 1.11 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
52
import express from 'express';
import mongoose from 'mongoose';
import helmet from 'helmet';
import cors from 'cors';
import bearerToken from 'express-bearer-token';
import { errorHandler } from './middlewares';
import router from './routes';
class App {
public app: express.Application;
constructor() {
this.app = express();
this.initializeMiddlewares();
this.connectMongoDB();
this.initializeRouter();
}
private initializeMiddlewares() {
this.app.use(helmet());
this.app.use(cors());
this.app.use(express.json());
this.app.use(express.urlencoded({ extended: true }));
this.app.use(
bearerToken({
bodyKey: 'token',
headerKey: 'Bearer',
}),
);
this.app.use(errorHandler);
}
// eslint-disable-next-line class-methods-use-this
private connectMongoDB() {
const mongooseOption = {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
};
mongoose.connect(`mongodb://localhost:27017/dimigoin`, mongooseOption);
}
private initializeRouter() {
this.app.use('/', router);
}
}
export default App;