Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const path = require("path");
const os = require("os");
const dotenv = require("dotenv");
const cors = require("cors");
const rateLimit = require('express-rate-limit');


dotenv.config();

Expand All @@ -21,11 +23,26 @@ const corsOptions = {
optionsSuccessStatus: 204,
};

// Configure RateLimiting
const apiLimiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
message: {
success: false,
error: 'Too many requests from this IP, please try again after 15 minutes'
},
standardHeaders: true,
legacyHeaders: false,
});

app.use(cors(corsOptions));

// Middleware to parse JSON bodies
app.use(express.json());

// Apply rate limiting to all routes
app.use(apiLimiter)

// Configure multer for file upload handling
const upload = multer({
storage: multer.memoryStorage(),
Expand Down