From ebbc1aa5b7a3f90ccbbd1607e4b7c5be1da08a90 Mon Sep 17 00:00:00 2001 From: LACKY <65214509+L0SER8228@users.noreply.github.com> Date: Fri, 23 Jun 2023 23:26:40 +0530 Subject: [PATCH] Add rate limit --- app.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app.js b/app.js index 0cea701..dafd27f 100644 --- a/app.js +++ b/app.js @@ -11,6 +11,15 @@ app.set("view engine", "ejs"); app.set("views", __dirname + "/views"); app.use(express.static(__dirname + "/public")); +// set up rate limiter: maximum of ten requests per minute +const RateLimit = require("express-rate-limit"); +const limiter = RateLimit({ + windowMs: 1*60*1000, // 1 minute + max: 10 +}); +// apply rate limiter to all requests +app.use(limiter); + // Routes app.get("/", (req, res) => { res.render("index", { error: null });