-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (32 loc) · 975 Bytes
/
server.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
const express = require("express");
const path = require("path");
const bodyParser = require('body-parser')
const { sequelize } = require("./models");
const { rootRouter } = require("./routers");
const cors = require('cors')
const app = express();
// cài ứng dụng sử dụng kiểu json
app.use(express.json());
app.use(express.json());
app.use(express.urlencoded({
extended: true,
})
);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json())
//alow cors
app.use(cors())
// cài static file
const publicPathDirectory = path.join(__dirname, "./public");
app.use("/public", express.static(publicPathDirectory));
// dùng router
app.use("/api/v1", rootRouter);
// lắng nghe sự kiện kết nối
app.listen(3001, async () => {
console.log("App listening on http://localhost:3001");
try {
await sequelize.authenticate();
} catch (error) {
console.error("Unable to connect to the database:", error);
}
});