-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (38 loc) · 831 Bytes
/
app.js
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
const express = require("express");
const dataSource = require("./lib/database/database");
const {
cors,
json,
body ,
helmet,
compression,
logger,
limiter,
} = require("./lib/middlewares");
const MainRouter = require("./api/routes/MainRouter");
const UserRouter = require("./api/routes/UserRouter");
const path = require("path");
const initApp = () => {
const app = express();
// middleware
app.use(body());
app.use(json());
app.use(cors());
app.use(helmet());
app.use(limiter());
app.use(compression());
app.use(logger());
// routers
app.use(MainRouter());
app.use(UserRouter());
return app
}
const initDb = async () => {
const connection = dataSource.initialize();
await (await connection).synchronize();
console.log("working...");
}
module.exports = {
initDb,
initApp,
}