-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (25 loc) Β· 1.1 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
// βΉοΈ 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");
const app = express();
// βΉοΈ This function is getting exported from the config folder. It runs most pieces of middleware
require("./config")(app);
const { isAuthenticated } = require("./middleware/jwt.middleware");
// π Start handling routes here
// Contrary to the views version, all routes are controlled from the routes/index.js
const allRoutes = require("./routes/index.routes");
app.use("/api", allRoutes);
const authRoutes = require("./routes/auth.routes");
app.use("/api/auth", authRoutes);
const userRoutes = require("./routes/user.routes");
app.use("/", userRoutes);
const appRoutes = require("./routes/app.routes");
app.use("/", appRoutes);
// β To handle errors. Routes that don't exist or errors that you handle in specific routes
require("./error-handling")(app);
module.exports = app;