-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
97 lines (76 loc) · 3.03 KB
/
app.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ==========================================================
MODULES
========================================================== */
const express = require("express");
const bodyParser = require("body-parser");
const helmet = require("helmet");
const mongoose = require("mongoose");
const passport = require("passport");
const session = require("express-session");
/* ==========================================================
VARIABLES
========================================================== */
if (process.env.NODE_ENV !== "production") require("dotenv").config();
const app = express();
/* ==========================================================
DATABASE
========================================================== */
mongoose.connect(process.env.MONGODB_URL, {
useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true
});
/* ==========================================================
SERVER
========================================================== */
app.listen(process.env.PORT, () => console.log(`Server is running at port ${process.env.PORT}`));
/* ==========================================================
MIDDLEWARES
========================================================== */
// Express Middleware: Serve Static Files (HTML, CSS, JS, Images)
app.use(express.static(__dirname));
// Parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// Parse application/json
app.use(bodyParser.json());
// Security
app.use(helmet({ contentSecurityPolicy: false }));
// X-XSS Header
app.use((req, res, next) => {
res.setHeader("X-XSS-Protection", "1; mode=block");
res.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload");
res.setHeader("X-Content-Type-Options", "nosniff");
res.removeHeader("X-Powered-By");
res.removeHeader("Server");
next();
});
/* ==========================================================
AUTHENTICATION
========================================================== */
// Session
app.use(session({
secret: process.env.SESSION_SECRET, saveUninitialized: true,
resave: true, rolling: true, sameSite: "none"
}));
// Passport
app.use(passport.initialize());
app.use(passport.session());
require("./configs/passport.js");
/* ==========================================================
ROUTERS
========================================================== */
const generalRouter = require("./routes/general.js");
app.use(generalRouter);
const accountRouter = require("./routes/account.js");
app.use(accountRouter);
const dashboardRouter = require("./routes/dashboard.js");
app.use(dashboardRouter);
const settingsRouter = require("./routes/settings.js");
app.use(settingsRouter);
const notificationsRouter = require("./routes/notifications.js");
app.use(notificationsRouter);
const verificationRouter = require("./routes/verification.js");
app.use(verificationRouter);
const testRouter = require("./routes/test.js");
app.use(testRouter);
/* ==========================================================
END
========================================================== */