From 659934760bbb9260eb588a77ca17b074bce6c6e8 Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:26:36 +0200 Subject: [PATCH] Add rate limiter for static routes --- src/app.mjs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app.mjs b/src/app.mjs index baf8b825..c0ed76a9 100644 --- a/src/app.mjs +++ b/src/app.mjs @@ -48,10 +48,11 @@ //Base routes const statics = path.resolve("src/html") - app.get("/", (req, res) => res.sendFile(`${statics}/index.html`)) - app.get("/index.html", (req, res) => res.sendFile(`${statics}/index.html`)) - app.get("/placeholder.svg", (req, res) => res.sendFile(`${statics}/placeholder.svg`)) - app.get("/favicon.ico", (req, res) => res.sendStatus(204)) + const limiter = ratelimit({max:60, windowMs:60*1000}) + app.get("/", limiter, (req, res) => res.sendFile(`${statics}/index.html`)) + app.get("/index.html", limiter, (req, res) => res.sendFile(`${statics}/index.html`)) + app.get("/placeholder.svg", limiter, (req, res) => res.sendFile(`${statics}/placeholder.svg`)) + app.get("/favicon.ico", limiter, (req, res) => res.sendStatus(204)) //Metrics app.get("/:login", ...middlewares, async (req, res) => {