-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
75 lines (65 loc) · 1.95 KB
/
Copy pathindex.js
File metadata and controls
75 lines (65 loc) · 1.95 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
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
import "dotenv/config";
import compression from "compression";
import express from "express";
import MySQLStore from "express-mysql-session";
import session from "express-session";
import expressWs from "express-ws";
import path from "path";
const app = express();
expressWs(app);
// *
app.disable("x-powered-by");
app.set("view engine","ejs");
app.use(compression());
const sessionStore = new (MySQLStore(session))({
host: process.env.dbHost,
user: process.env.dbUser,
password: process.env.dbPassword,
database: process.env.dbName,
clearExpired: true,
checkExpirationInterval: 1209600000, // 2 weeks
expiration: 2419200000, // 4 weeks
createDatabaseTable: false
});
app.use(session({
secret: process.env.cookieSecret,
saveUninitialized: false,
resave: false,
unset: "destroy",
store: sessionStore,
cookie: {
maxAge: 2419200000, // 4 weeks
httpOnly: true,
// secure: process.env.cookieSecure,
sameSite: "strict"
},
}));
// static files
if (process.env.NODE_ENV === "production") {
app.use("/css", express.static(path.join("public", "cssMinified")));
app.use("/js", express.static(path.join("public", "jsMinified")));
}
app.use(express.static("public"));
//
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use("/", (await import("./routes/pages.js")).default);
app.use("/profile", (await import("./routes/profile.js")).default);
app.use("/admin", (await import("./routes/admin.js")).default);
// ** //
// **404 handler //
app.use((req,res) => {
res.status(404);
if (req.accepts("html")) {
return res.render("404", { displayName: req.session.displayName || "No user" , path: req.path});
}
if (req.accepts("json")) {
return res.json({message:"not found"});
}
res.type("txt").send("not found");
});
// ** //
app.listen(process.env.serverPort, () => {
process.title = `Gatekeep Server | ${process.env.serverPort}`;
console.log(`Server is running on http://localhost:${process.env.serverPort} || ${process.env.NODE_ENV}`);
});