generated from wecode-bootcamp-korea/backend-1st-project-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
49 lines (37 loc) · 1.12 KB
/
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
46
47
48
49
const http = require("http");
const express = require("express");
const dotenv = require("dotenv");
const cors = require("cors");
const morgan = require("morgan");
dotenv.config();
const { AppDataSource } = require("./src/models/data-source");
const { routes } = require("./src/routes");
const { validateToken } = require("./src/middleware/auth");
const app = express();
app.use(cors());
app.use(express.json()); // for parsing application/json
app.use(morgan("combined"));
app.use(routes);
app.get("/", async (req, res) => {
try {
return res.status(200).json({ message: "Welcome" });
} catch (err) {
console.log(err);
}
});
app.get("/ping", async (req, res) => {
return res.status(200).json({ message: "pong" });
});
const server = http.createServer(app); // express app 으로 서버를 만듭니다.
const start = async () => {
// 서버를 시작하는 함수입니다.
try {
await AppDataSource.initialize().then(() =>
console.log("Datasource initialized.")
);
server.listen(8000, () => console.log(`Server is listening on 8000`));
} catch (err) {
console.error(err);
}
};
start();