mirror of
https://github.com/strapi/strapi.git
synced 2025-07-29 11:58:29 +00:00
pr feedback
Signed-off-by: Derrick Mehaffy <derrickmehaffy@gmail.com>
This commit is contained in:
parent
7576d8a257
commit
cf4b74c4f4
@ -9,10 +9,12 @@ module.exports =
|
|||||||
async (ctx, next) => {
|
async (ctx, next) => {
|
||||||
const ratelimit = require('koa2-ratelimit').RateLimit;
|
const ratelimit = require('koa2-ratelimit').RateLimit;
|
||||||
|
|
||||||
|
const userEmail = ctx.request.body.email || 'unknownEmail';
|
||||||
|
|
||||||
return ratelimit.middleware({
|
return ratelimit.middleware({
|
||||||
interval: { min: 15 },
|
interval: { min: 5 },
|
||||||
max: 5,
|
max: 5,
|
||||||
prefixKey: `${ctx.request.path}:${ctx.request.ip}`,
|
prefixKey: `${userEmail}${ctx.request.path}:${ctx.request.ip}`,
|
||||||
handler() {
|
handler() {
|
||||||
throw new RateLimitError();
|
throw new RateLimitError();
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const createError = require('http-errors');
|
const createError = require('http-errors');
|
||||||
const { NotFoundError, UnauthorizedError, ForbiddenError, PayloadTooLargeError, PolicyError } =
|
const { NotFoundError, UnauthorizedError, ForbiddenError, PayloadTooLargeError, RateLimitError } =
|
||||||
require('@strapi/utils').errors;
|
require('@strapi/utils').errors;
|
||||||
|
|
||||||
const mapErrorsAndStatus = [
|
const mapErrorsAndStatus = [
|
||||||
@ -22,7 +22,7 @@ const mapErrorsAndStatus = [
|
|||||||
status: 413,
|
status: 413,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
classError: PolicyError,
|
classError: RateLimitError,
|
||||||
status: 429,
|
status: 429,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user