-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (46 loc) · 1.54 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
// Importing the express library
const express = require("express");
// Importing the user router
const userRouter = require("./routes/userRoutes");
// Importing the project router
const projectRouter = require("./routes/projectRoutes");
// Importing the task router
const taskRouter = require("./routes/taskRoutes");
// Importing the sub tasks router
const subTaskRouter = require("./routes/subTaskRoutes");
// Importing the morgan library to log requests
const morgan = require("morgan");
// Importing the cors library
const cors = require("cors");
// Importing the cookie parser library
const cookieParser = require("cookie-parser");
// Custom error handler middleware
const errorHandler = require("./utils/Error");
// Adding the notification job
require("./jobs/NotificationJob");
// Creating an express application
const app = express();
// Adding the cors middleware to allow cross-origin requests
app.use(
cors({
origin: "https://pro-manager-tool.netlify.app",
credentials: true,
})
);
// Serving static files from the 'uploads' directory
app.use("/uploads", express.static("uploads"));
// parse the cookies of the request
app.use(cookieParser());
// Adding middleware to parse the request body
app.use(express.json());
// to log requests
app.use(morgan("dev"));
// Creating routes
app.use("/api/v1/users", userRouter);
app.use("/api/v1/projects", projectRouter);
app.use("/api/v1/projects", taskRouter);
app.use("/api/v1/tasks", subTaskRouter);
// Handle 404 error
app.use(errorHandler);
// Export the express app
module.exports = app;