From ffb65bdfa58ac862e417a8271c2ec3552c9c4135 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Sat, 27 Jul 2024 21:47:07 +0530 Subject: added rate limiting to the api --- backend/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/index.js b/backend/index.js index 7b548ad..9693dcd 100644 --- a/backend/index.js +++ b/backend/index.js @@ -36,6 +36,16 @@ const db = admin.firestore(); // Secret key for JWT const JWT_SECRET = process.env.JWT_SECRET_KEY; +// Rate Limiting middleware +const limiter = rateLimit({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 100, // limit each IP to 100 requests per windowMs + message: 'Too many requests from this IP, please try again after 15 minutes', +}); + +// Apply rate limiter to all requests +app.use(limiter); + // Register route app.post('/register', async (req, res) => { const { username, password } = req.body; -- cgit v1.2.3-59-g8ed1b