forked from kartikeya-123/Hacko-4-code4bbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (57 loc) · 2.04 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
65
66
67
68
69
70
71
72
const express = require("express");
const cors = require("cors");
const helmet = require("helmet");
const cookieParser = require("cookie-parser");
const mongoSanitize = require("express-mongo-sanitize");
const xss = require("xss-clean");
const path = require("path");
const middleware = require("./utils/middleware");
const clientEndpoints = ["discover", "profile", "update"];
const AppError = require("./utils/appError");
const globalErrorHandler = require("./controller/errorController");
const userRouter = require("./routes/userRoutes");
const authRouter = require("./routes/authRoutes");
const searchRouter = require("./routes/searchRoutes");
const sportRouter = require("./routes/sportRoutes");
const complaintRouter = require("./routes/complaintRoutes");
const courseRouter = require("./routes/courseRoutes");
const timeTableRouter = require("./routes/timeTableRoutes");
const messRouter = require("./routes/menuRoutes");
// const adminRouter = require('./routes/adminRoutes');
// require('./cronJobs/backup');
const app = express();
app.use(helmet());
app.use(
cors({
origin: "http://localhost:3001",
credentials: true,
})
);
app.use(xss());
app.use(cookieParser());
app.use(express.json({ limit: "10kb" }));
app.use(mongoSanitize());
app.use(middleware.requestLogger);
app.use(express.static(path.join(__dirname, "client/build")));
//Authentication Endpoint
app.use("/api/v1/auth", authRouter);
//Sport Equipment routes
app.use("/api/v1/sport", sportRouter);
//Complaint Routes
app.use("/api/v1/complaint", complaintRouter);
app.use("/api/v1/course", courseRouter);
app.use("/api/v1/timetable", timeTableRouter);
//user routes
app.use("/api/v1/user", userRouter);
//Menu Routes
app.use("/api/v1/mess", messRouter);
//Search Endpoints
app.use("/api/v1/search", searchRouter);
app.get("*", (req, res, next) => {
res.sendFile(path.join(__dirname, "/client/build/index.html"));
});
// app.all("*", (req, res, next) => {
// next(new AppError(`Can't find ${req.originalUrl} on this server!`, 404));
// });
app.use(globalErrorHandler);
module.exports = app;