-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (33 loc) · 1.04 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
const express = require("express");
const morgan = require("morgan");
const blogRouter = require("./routes/blogRoutes");
const userRouter = require('./routes/userRoutes');
const cookieParser = require('cookie-parser');
const fs = require('fs');
const path = require('path');
const rateLimit = require('express-rate-limit');
// Ensure the uploads directory exists
const uploadsDir = path.join(__dirname, 'uploads');
if (!fs.existsSync(uploadsDir)) {
fs.mkdirSync(uploadsDir, { recursive: true });
}
const app = express();
const apiLimit = rateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
message: 'Too many request from this IP. Try again later',
headers: true, // Include rate limit headers in the response
});
// Middlewares
app.use(morgan("dev"));
app.use(express.json());
app.use(cookieParser()); // Cookie parser middleware
app.use(apiLimit);
// Routes
app.use("/api/v1/blogs", blogRouter);
app.use("/api/v1/user", userRouter);
app.get('/hello-world',(req,res)=>{
res.send("<b>Hello World</b>")
})
// Exporting app
module.exports = app;