Session config moved to it's own file and attached to app.js
This commit is contained in:
@@ -13,11 +13,11 @@
|
|||||||
></script>
|
></script>
|
||||||
|
|
||||||
<!-- Homepage Scripts -->
|
<!-- Homepage Scripts -->
|
||||||
<script src="/routes/league-pages/redirect-to-league-url.js"></script>
|
<script src="/src/routes/league-pages/redirect-to-league-url.js"></script>
|
||||||
|
|
||||||
<!-- League Pages Scripts -->
|
<!-- League Pages Scripts -->
|
||||||
<script src="/js/league-page/change-goal-difference-color.js"></script>
|
<script src="/js/league-page/change-goal-difference-color.js"></script>
|
||||||
<script src="/routes/club-pages/redirect-to-club-url.js"></script>
|
<script src="/src/routes/club-pages/redirect-to-club-url.js"></script>
|
||||||
|
|
||||||
<!-- Club Pages Scripts -->
|
<!-- Club Pages Scripts -->
|
||||||
<script src="/js/club-page/favorite-button.js"></script>
|
<script src="/js/club-page/favorite-button.js"></script>
|
||||||
|
|||||||
34
src/app.js
34
src/app.js
@@ -42,38 +42,8 @@ app.use(bodyParser.json()); // specify the usage of JSON for parsing request bod
|
|||||||
// <!-- Section 5 : Website Routes -->
|
// <!-- Section 5 : Website Routes -->
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
|
|
||||||
// initialize session variables
|
const sessionConfig = require("./config/session"); // Import the hbs module
|
||||||
app.get("/welcome", (req, res) => {
|
sessionConfig(app);
|
||||||
res.json({ status: "success", message: "Welcome!" });
|
|
||||||
});
|
|
||||||
app.use(
|
|
||||||
session({
|
|
||||||
secret: process.env.SESSION_SECRET,
|
|
||||||
saveUninitialized: false,
|
|
||||||
resave: false,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
app.use(
|
|
||||||
bodyParser.urlencoded({
|
|
||||||
extended: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
app.use(async function (req, res, next) {
|
|
||||||
res.locals.user = req.session.user;
|
|
||||||
|
|
||||||
if (res.locals.user) {
|
|
||||||
try {
|
|
||||||
res.locals.fav_teams = await getFavoriteTeamsForUser(
|
|
||||||
res.locals.user.userid
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching favorite teams:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
// <!-- Section 4 : Middleware -->
|
// <!-- Section 4 : Middleware -->
|
||||||
|
|||||||
Reference in New Issue
Block a user