-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
57 lines (43 loc) · 1.62 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
// ℹ️ Gets access to environment variables/settings
// https://www.npmjs.com/package/dotenv
require("dotenv/config");
// ℹ️ Connects to the database
require("./db");
// Handles http requests (express is node js framework)
// https://www.npmjs.com/package/express
const express = require("express");
// Handles the handlebars
// https://www.npmjs.com/package/hbs
const hbs = require("hbs");
const app = express();
// ℹ️ This function is getting exported from the config folder. It runs most pieces of middleware
require("./config")(app);
const projectName = "secretsanta";
const capitalized = (string) =>
string[0].toUpperCase() + string.slice(1).toLowerCase();
app.locals.title = `${capitalized(projectName)} created with IronLauncher`;
app.use((req, res, next) => {
res.locals.userIsConnected = req.session.user ? true : false;
if (res.locals.userIsConnected) {
res.locals.username = req.session.user.username;
res.locals.profileImg = req.session.user.profileImg;
res.locals._id = req.session.user._id;
}
next();
});
// 👇 Start handling routes here
const index = require("./routes/index");
app.use("/", index);
//authentication routes here
const authRoutes = require("./routes/auth");
app.use("/auth", authRoutes);
//group routes here
const groupRoutes = require("./routes/group");
app.use("/group", groupRoutes);
//user routes here
const userRoutes = require("./routes/user");
const res = require("express/lib/response");
app.use("/user", userRoutes);
// ❗ To handle errors. Routes that don't exist or errors that you handle in specific routes
require("./error-handling")(app);
module.exports = app;