I am trying to add a middleware in strapi custom route which can control how many requests can come from a specific IP> For this I am using express-rate-limit but its not working
I tried this:
const rateLimit = require("express-rate-limit");
module.exports = () => {
return async (ctx, next) => {
await next();
rateLimit({
windowMs: 60 * 1000, // 1 minutes
max: 3, // Limit each IP to 3 requests per windowMs
message: "too many requests",
});
};
};
Custom route:
{
method: "GET",
path: "/v1/customer/social/accounts",
handler: "customer.getSocialAccounts",
config: {
auth: false,
middlewares: ["global::jwtVerify", "global::rate-limit"],
},
},
But its not giving me the desired output like if I hit more then 3 requests then it should give too many requests error(429).