-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
81 lines (60 loc) · 1.82 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
const express = require("express");
const exphbs = require("express-handlebars");
const handlebars = require("handlebars");
const path = require("path");
const passport = require("passport");
const session = require("express-session");
const methodOverride = require("method-override");
const connectDatabase = require("./configuration/database");
const {
allowInsecurePrototypeAccess,
} = require("@handlebars/allow-prototype-access");
const app = express();
// connect database
connectDatabase();
const port = process.env.PORT || 5000;
const Theme = require("./models/Theme");
// passport setup
app.use(session({ secret: "keyboard cat" }));
app.use(passport.initialize());
app.use(passport.session());
require("./configuration/auth");
// set data for view
app.use((req, res, next) => {
res.locals.user = req.user;
res.locals.currentTheme = null;
if (app.locals.mytheme) {
res.locals.currentTheme = app.locals.mytheme;
}
next();
});
// override with POST having ?_method=DELETE
app.use(methodOverride("_method"));
// set public access for application
app.use(express.static(path.join(__dirname, "public")));
// express-handlebars middleware
app.engine(
"handlebars",
exphbs({
handlebars: allowInsecurePrototypeAccess(handlebars),
})
);
app.set('view engine', 'handlebars');
// middleware
app.use(express.urlencoded({ extended: true }));
app.get("/", async (req, res) => {
const themes = await Theme.find({});
res.render("home", {
themes: themes,
});
});
app.get("/about", (req, res) => {
res.render("pages/about");
});
app.get("/contact", (req, res) => {
res.render("pages/contact");
});
// load our all routes here
app.use("/dashboard", require("./routes/dashboard"));
app.use("/themes", require("./routes/themes"));
app.listen(port, () => console.log("server started at: 5000"));