feat(rate-limit): add more config options

Allow the admin to specify the rate-limits for user signup / login
Allow the admin to specify if Cloudflare specific rate-limit functionality should be used or not

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares
2026-06-10 21:00:43 +02:00
committed by Philip Molares
parent d7c1e45814
commit 8891d75baa
5 changed files with 32 additions and 21 deletions

View File

@@ -8,13 +8,16 @@ const determineKey = (req) => {
if (req.user) {
return req.user.id
}
return ipKeyGenerator(req.header('cf-connecting-ip') || req.ip)
if (config.rateLimitUsingCloudflare) {
return ipKeyGenerator(req.header('cf-connecting-ip') || req.ip)
}
return ipKeyGenerator(req.ip)
}
// limits requests to user endpoints (login, signup) to 10 requests per 5 minutes
const userEndpoints = rateLimit({
windowMs: 5 * 60 * 1000,
limit: 10,
limit: config.rateLimitUser,
keyGenerator: determineKey,
handler: (req, res) => errors.errorTooManyRequests(res)
})