Skip to content

Commit

Permalink
refactor config loading
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickmehaffy committed Dec 27, 2022
1 parent 2f87da5 commit 33bd405
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/core/admin/server/middlewares/rateLimit.js
Expand Up @@ -10,18 +10,22 @@ module.exports =
async (ctx, next) => {
let ratelimitConfig = strapi.config.get('admin.ratelimit');

if (!ratelimitConfig || !has('enabled', ratelimitConfig)) {
if (!ratelimitConfig) {
ratelimitConfig = {
enabled: true,
};
}

if (!has('enabled', ratelimitConfig)) {
ratelimitConfig.enabled = true;
}

if (ratelimitConfig.enabled === true) {
const ratelimit = require('koa2-ratelimit').RateLimit;

const userEmail = toLower(ctx.request.body.email) || 'unknownEmail';

return ratelimit.middleware({
const loadConfig = {
interval: { min: 5 },
max: 5,
prefixKey: `${userEmail}:${ctx.request.path}:${ctx.request.ip}`,
Expand All @@ -30,7 +34,11 @@ module.exports =
},
...ratelimitConfig,
...config,
})(ctx, next);
};

console.log(loadConfig);

return ratelimit.middleware(loadConfig)(ctx, next);
}

return next();
Expand Down

0 comments on commit 33bd405

Please sign in to comment.