-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (35 loc) · 1.09 KB
/
index.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
const express = require("express");
const app = express();
const port = 3000;
const expressHbs = require("express-handlebars");
const { createPagination } = require("express-handlebars-paginate");
//config for json
app.use(express.json()); //Middleware để đọc dữ liệu từ form gửi lên qua post --> parse ra json
app.use(express.urlencoded({extended: true}));
app.use(express.static(__dirname + "/html"));
app.engine(
"hbs",
expressHbs.engine({
layoutsDir: __dirname + "/views/layouts",
defaultLayout: "layout",
extname: "hbs",
runtimeOptions: {
allowProtoPropertiesByDefault: true,
},
helpers: {
createPagination,
formatDate: (date) => {
return date.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
});
},
showIndex: (index) => index + 1,
},
})
);
app.set("view engine", "hbs");
app.get("/", (req, res) => res.redirect("/users"));
app.use("/users", require("./routes/userRouter"));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));