pr feedback

Signed-off-by: Derrick Mehaffy <derrickmehaffy@gmail.com>
This commit is contained in:
derrickmehaffy 2022-10-07 07:50:26 -07:00 committed by DMehaffy
parent 7576d8a257
commit cf4b74c4f4
2 changed files with 6 additions and 4 deletions

View File

@ -9,10 +9,12 @@ module.exports =
async (ctx, next) => {
const ratelimit = require('koa2-ratelimit').RateLimit;
const userEmail = ctx.request.body.email || 'unknownEmail';
return ratelimit.middleware({
interval: { min: 15 },
interval: { min: 5 },
max: 5,
prefixKey: `${ctx.request.path}:${ctx.request.ip}`,
prefixKey: `${userEmail}${ctx.request.path}:${ctx.request.ip}`,
handler() {
throw new RateLimitError();
},

View File

@ -1,7 +1,7 @@
'use strict';
const createError = require('http-errors');
const { NotFoundError, UnauthorizedError, ForbiddenError, PayloadTooLargeError, PolicyError } =
const { NotFoundError, UnauthorizedError, ForbiddenError, PayloadTooLargeError, RateLimitError } =
require('@strapi/utils').errors;
const mapErrorsAndStatus = [
@ -22,7 +22,7 @@ const mapErrorsAndStatus = [
status: 413,
},
{
classError: PolicyError,
classError: RateLimitError,
status: 429,
},
];