mirror of
https://github.com/strapi/strapi.git
synced 2025-07-29 11:58:29 +00:00
23 lines
512 B
JavaScript
23 lines
512 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const utils = require('@strapi/utils');
|
||
|
|
||
|
const { RateLimitError } = utils.errors;
|
||
|
|
||
|
module.exports =
|
||
|
(config, { strapi }) =>
|
||
|
async (ctx, next) => {
|
||
|
const ratelimit = require('koa2-ratelimit').RateLimit;
|
||
|
|
||
|
return ratelimit.middleware({
|
||
|
interval: { min: 15 },
|
||
|
max: 5,
|
||
|
prefixKey: `${ctx.request.path}:${ctx.request.ip}`,
|
||
|
handler() {
|
||
|
throw new RateLimitError();
|
||
|
},
|
||
|
...strapi.config.get('admin.ratelimit'),
|
||
|
...config,
|
||
|
})(ctx, next);
|
||
|
};
|