mirror of
https://github.com/strapi/strapi.git
synced 2025-07-26 02:20:32 +00:00
28 lines
623 B
JavaScript
28 lines
623 B
JavaScript
'use strict';
|
|
|
|
module.exports =
|
|
(config, { strapi }) =>
|
|
async (ctx, next) => {
|
|
const ratelimit = require('koa2-ratelimit').RateLimit;
|
|
|
|
const message = [
|
|
{
|
|
messages: [
|
|
{
|
|
id: 'Auth.form.error.ratelimit',
|
|
message: 'Too many attempts, please try again in a minute.',
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
return ratelimit.middleware({
|
|
interval: 1 * 60 * 1000,
|
|
max: 5,
|
|
prefixKey: `${ctx.request.path}:${ctx.request.ip}`,
|
|
message,
|
|
...strapi.config.get('plugin.users-permissions.ratelimit'),
|
|
...config,
|
|
})(ctx, next);
|
|
};
|