-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
77 lines (64 loc) · 1.84 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
require("dotenv").config();
const express = require("express");
const fileUpload = require("express-fileupload");
const session = require("express-session");
const passport = require("./config/passport");
const flash = require("connect-flash");
const helmet = require("helmet");
const cors = require("cors");
const authRouter = require("./routes/auth");
const homeRouter = require("./routes/home");
const svboardsRouter = require("./routes/savedBoards");
const sboardsRouter = require("./routes/soundBoards");
const accountsRouter = require("./routes/accounts");
const handleError = require("./middlewares/handleError");
const app = express();
const port = process.env.PORT || 3000;
app.set("view engine", "ejs");
//not sure what i'm doing here
app.use(cors({ origin: true }));
app.use(
helmet({
contentSecurityPolicy: {
useDefaults: true,
directives: {
"script-src": ["'self'", "https://cdn.jsdelivr.net"],
"style-src": ["'self'", "https://cdn.jsdelivr.net"],
"media-src": ["data:", "'self'"],
},
},
})
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
})
);
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(
fileUpload({
safeFileNames: false,
})
);
app.use(function (req, res, next) {
res.locals.success = req.flash("success");
res.locals.errors = req.flash("errors");
next();
});
app.get("/", (req, res) => res.redirect("/home"));
app.use("/static", express.static("public"));
app.use("/auth", authRouter);
app.use("/account", accountsRouter);
app.use("/home", homeRouter);
app.use("/savedboards", svboardsRouter);
app.use("/soundboards", sboardsRouter);
app.use(handleError);
app.listen(port, () => {
console.log(`App listening in http://localhost:${port}`);
});