-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (50 loc) · 1.77 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
const express = require("express");
const morgan = require("morgan");
const path = require("path");
const compression = require("compression");
const app = express();
const xss = require("xss-clean");
const mongoSanitize = require("express-mongo-sanitize");
const helmet = require("helmet");
const rateLimit = require("express-rate-limit");
const cors = require("cors");
const AppError = require("./utils/appError");
app.use(compression());
app.use(express.urlencoded({ extended: false }));
app.use(express.json({ limit: "10kb" }));
app.use(express.static(path.join(__dirname, "public")));
if (process.env.NODE_ENV == "development") {
app.use(morgan("dev"));
}
app.use(mongoSanitize());
app.use(helmet());
app.use(xss());
const limiter = rateLimit({
windowMs: 10 * 60 * 1000,
max: 500,
message: `Too many requests from this IP , please try again in an hour`,
});
app.use(cors());
app.use("/api", limiter);
const homeRouter = require("./routes/homeRoutes");
const authRouter = require("./routes/authRoutes")
const apiRoutes = require("./routes/apiRoutes")
const publicRouter = require("./routes/publicRoutes")
const sastoRouter = require("./routes/scrapPetFood")
app.use("/static", express.static(path.join(__dirname, "static")));
app.use("/api/scrap", homeRouter);
app.use("/api/auth",authRouter)
app.use("/api/endpoints",apiRoutes)
app.use("/api/public",publicRouter)
app.use("/api/petfood",sastoRouter)
// app.all("*", (req, res, next) => {
// return next(new AppError(`can't find ${req.originalUrl} on this server`))
// });
// if(process.env.NODE_ENV==="production"){
// app.use(express.static('client/build'));
// app.get('*',(req, res)=>{
// res.sendFile(path.resolve(__dirname,'client','build','index.html'))
// })
// }
// app.use(globalErrorHandler);
module.exports = app;