-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (37 loc) · 1.27 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
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const rateLimit = require("express-rate-limit");
const { notFound } = require("./errorHandler/notFound");
const { authRouter } = require("./routes/authRoutes");
const { homeRouter } = require("./routes/homeRoutes");
const { cartRouter } = require("./routes/cartRoutes");
const { orderRouter } = require("./routes/orderRoutes");
const { errorHanlding } = require("./errorHandler/errorHandler");
require("dotenv").config();
const app = express();
const limiter = rateLimit({
windowMs: 5 * 60 * 1000, // 5 minutes
max: 25, // Limit each IP to 25 requests per windowMs
});
app.use(limiter);
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use("/auth", authRouter);
app.use("/cart", cartRouter);
app.use("/order", orderRouter);
app.use("/", homeRouter);
app.use(notFound);
app.use(errorHanlding);
mongoose.set("strictQuery", true);
mongoose
.connect(process.env.MONGODB)
.then((val) => {
console.log(`Connted To Db ${val}`);
app.listen(process.env.PORT, () => {
console.log(`currently ON ${process.env.PORT}`);
});
})
.catch((err) => {
console.log(`Failed To Connected To DB ${err}`);
});