-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (26 loc) · 846 Bytes
/
Copy pathindex.js
File metadata and controls
32 lines (26 loc) · 846 Bytes
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
// Khai báo và config thư viện + config file .env
import express from "express";
import cors from "cors";
import initRoute from "./src/routes";
require("dotenv").config();
require("./src/config/connectDatabase");
// Khai báo app và chạy server
const app = express();
// Config cors chỉ cho phép url truy cap
app.use(
cors({
origin: process.env.CLIENT_URL,
methods: ["GET", " POST", " PUT", "DELETE"],
})
);
// Config req.body cho phép server đọc đc json
app.use(express.json());
// Config req.body cho phép server đọc đc urlencoded
app.use(express.urlencoded({ extended: true }));
// Chạy hàm route cho server
initRoute(app);
const port = process.env.PORT || 8002;
// Chạy server
const listener = app.listen(port, () => {
console.log(`Example app listening on port ${listener.address().port}`);
});