-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (32 loc) · 1.18 KB
/
Copy pathindex.js
File metadata and controls
40 lines (32 loc) · 1.18 KB
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
require("dotenv").config();
const express = require("express");
const database = require("./config/database");
const systemConfig = require("./config/system");
const clientRoutes = require("./routes/client/index.routes.js");
const adminRoutes = require("./routes/admin/index.routes.js");
const bodyParser = require("body-parser");
const methodOverride = require("method-override");
const cors = require("cors");
const app = express();
const port = process.env.PORT || 3000;
// 1. Cài đặt Middleware
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.json());
app.use(methodOverride("_method"));
// 2. Kết nối Cơ sở dữ liệu MongoDB
database.connect();
// 3. Cấu hình View Engine (Pug)
app.set("views", "./views");
app.set("view engine", "pug");
// 4. Cấu hình biến dùng chung trong toàn bộ các file Pug template
app.locals.prefixAdmin = systemConfig.prefixAdmin;
// 5. Cấu hình thư mục chứa file tĩnh
app.use(express.static("public"));
// 6. Kết nối Routes
clientRoutes(app);
adminRoutes(app);
// 7. Khởi động server
app.listen(port, () => {
console.log(`🚀 Server đang chạy tại http://localhost:${port}`);
});