generated from wecode-bootcamp-korea/backend-2nd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (30 loc) · 991 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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const { router } = require("./api/routes");
const { dataSource } = require("./api/models/dataSource");
const { globalErrorHandler } = require("./api/utils/error");
const { updatePendingToCanceled } = require("./api/models/bookingDao");
const app = express();
app.use(cors());
app.use(morgan("combined"));
app.use(express.json());
app.use(router);
app.use(globalErrorHandler);
const PORT = process.env.PORT || 8000;
app.get("/ping", (req, res) => {
res.status(200).json({ message: "pong" });
});
setInterval(updatePendingToCanceled, 60000);
app.listen(PORT, async () => {
await dataSource
.initialize()
.then(() => {
console.log("Data Source has been initialized!");
})
.catch((error) => {
console.error("Error during Data Source initialization", error);
});
console.log(`Listening to request on port: ${PORT}`);
});