-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
75 lines (65 loc) · 1.84 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const express = require("express");
const path = require("path");
const server = express();
const expressHandleBars = require("express-handlebars");
const expressHandlebarsSections = require("express-handlebars-sections");
const morgan = require("morgan");
const bodyParser = require("body-parser");
const expressSession = require("express-session");
require("express-async-errors");
server.engine(
"hbs",
expressHandleBars({
extname: ".hbs",
layoutsDir: "views/_layouts",
partialsDir: "views/_partials",
helpers: {
section: expressHandlebarsSections(),
},
})
);
//server.use(morgan("dev"));
//server.use(express.json());
server.use(bodyParser.urlencoded({ extended: false }));
server.use(bodyParser.json());
server.set("view engine", "hbs");
server.use("/utils", express.static("utils"));
server.use(
expressSession({
secret: "sc",
resave: false,
saveUninitialized: true,
authUser: {},
})
);
server.use(express.static(path.join(__dirname, "./client/html&css")));
server.use(
"/vendor",
express.static(path.join(__dirname, "./client/html&css/vendor"))
);
server.use(
"/css",
express.static(path.join(__dirname, "./client/html&css/css"))
);
server.use(
"/assets",
express.static(path.join(__dirname, "./client/html&css/assets"))
);
server.use(require("./routes/home.route"));
server.use(require("./routes/admin.route"));
server.use(require("./routes/privilege.route"));
server.use(require("./routes/user.route"));
server.use(require("./routes/role.route"));
server.get("*", function (req, res) {
res.render("vwError/404", {
layout: "admin",
});
});
server.use(function (er, req, res, next) {
console.log("Asycn error: ", er.stack);
res.join({ error_message: er.stack });
});
const PORT = 1212;
server.listen(PORT, () => {
console.log(`Server is listening at ${PORT}\nURL: http://localhost:1212/`);
});