Session config moved to it's own file and attached to app.js

This commit is contained in:
2024-05-29 01:05:34 -05:00
parent b8e4fa5473
commit 32fc1ff745
2 changed files with 4 additions and 34 deletions

View File

@@ -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>

View File

@@ -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 -->