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:
committed by
Philip Molares
parent
d7c1e45814
commit
8891d75baa
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user