-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
70 lines (56 loc) · 1.86 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
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const helmet = require("helmet");
const morgan = require("morgan");
const cors = require("cors");
const rateLimit = require("express-rate-limit");
const mongoSanitize = require("express-mongo-sanitize");
const xssClean = require("xss-clean");
const globalErr = require("./controllers/errController");
const AppErr = require("./utils/appErr");
const userRoute = require("./routes/users");
const authRoute = require("./routes/auth");
const postRoute = require("./routes/post");
const commentRoute = require("./routes/comments");
const likeRoute = require("./routes/likes");
const credentials = require("./middleware/credentials");
const corOptions = require("./config/corOptions");
const App = express();
// const limiter = rateLimit({
// max: 200,
// windowMs: 60 * 60 * 1000,
// message: "Too many requests for this IP, please try again in an hour",
// });
App.use(helmet());
// App.use(limiter);
App.use(credentials);
App.use(cors(corOptions));
// App.use(cors({
// origin: 'https://tumlr-ani.netlify.app'
// }));
// App.options("*", cors());
App.use(express.static(path.join(__dirname, "public")));
App.use(express.json());
App.use(express.urlencoded({ extended: true }));
App.use(mongoSanitize());
App.use(xssClean());
App.use(cookieParser());
App.use(morgan("dev"));
App.use((req, _res, next) => {
req.requesTime = new Date().toISOString();
next();
});
App.use("/comments", commentRoute);
App.use(likeRoute);
App.use("/users", userRoute);
App.use("/auth", authRoute);
App.use("/posts", postRoute);
App.get("/", (_req, res, _next) => {
res.status(201).json({ message: "Welcome to devTalk blog API" });
});
App.all("*", (req, _res, next) => {
next(new AppErr(`Can't find ${req.originalUrl} on this server!`, 404));
});
App.use(globalErr);
module.exports = App;