-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
59 lines (51 loc) · 1.81 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
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");
//routers
const quoraRouter = require("./routes/quoraRoutes");
const authRouter = require("./routes/authRoutes.js");
const userRouter = require("./routes/userRoutes.js");
const searchRouter = require("./routes/searchRoutes.js");
const projectRouter = require("./routes/projectRoutes");
const courseRouter = require("./routes/courseRoutes");
const adminRouter = require("./routes/adminRoutes");
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.set("view engine", "html");
app.use(middleware.requestLogger);
// Serving static files
app.use(express.static(path.join(__dirname, "client/build")));
// API Endpoints
app.use("/api/v1/auth", authRouter);
app.use("/api/v1/user", userRouter);
app.use("/api/v1/quora", quoraRouter);
app.use("/api/v1/search", searchRouter);
app.use("/api/v1/project", projectRouter);
app.use("/api/v1/course", courseRouter);
app.use("/api/v1/admin", adminRouter);
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;