This middleware stores ip address of a request in memory and will throw an 429 Too Many Requests
error when there will be too many requests than the number set in the configuration. Based on https://github.com/jhurliman/node-rate-limiter and https://github.com/ptarjan/node-cache
It will help you solve this security problem.
export type RateLimiter = { tokensPerInterval: number; interval: string | number; fireImmediately?: boolean;};
To write a custom logic for this middleware follow this pattern:
export default defineNuxtConfig({ security: { rateLimiter: { tokensPerInterval: 200, interval: "day", fireImmediately: false throwError: false, // optional } }})
Or use routeRules
for per route configuration:
export default defineNuxtConfig({ routeRules: { '/my-secret-route': { security: { rateLimiter: { tokensPerInterval: 200, interval: "day", fireImmediately: false throwError: false, // optional } } } }