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