-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (28 loc) · 1.01 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
const express = require("express");
const cors = require("cors");
const rateLimit = require("express-rate-limit");
const globalErrorHandler = require("./controller/errorController");
const AppError = require("./utils/appError");
const authRouter = require("./routes/authRoute");
const postRouter = require("./routes/postRoute");
const communityRouter = require("./routes/communityRoute");
const authExtractor = require("./middleware/authExtractor");
const app = express();
app.use(cors());
app.use(express.json());
const limiter = rateLimit({
max: 100,
windows: 60 * 60 * 1000,
message: "Too many request from this IP, please try again in an hour!",
});
app.use("/api", limiter);
// app.use("/api/Login", authRouter);
// app.use("/api/signup", authRouter);
app.use("/api/auth", authRouter);
app.use("/api/c/", authExtractor, communityRouter);
//Error handling
app.all("*", (req, res, next) => {
next(new AppError(`Can't find ${req.originalUrl} on this server`, 404));
});
app.use(globalErrorHandler);
module.exports = app;