/**
* Define HTTP limiters
*
* The "limiter.define" method creates an HTTP middleware to apply rate limits on a route or a group of routes. Feel free to define as many throttle middleware as needed.
*/
import { APP_KEY, APP_KEY_HEADER_NAME } from "#config/app.ts"
import app from "@adonisjs/core/services/app"
import type { HttpLimiter } from "@adonisjs/limiter"
import limiter from "@adonisjs/limiter/services/main"
export const throttle = limiter.define("global", (context) => {
if (app.inTest || context.request.header(APP_KEY_HEADER_NAME) === APP_KEY) {
return limiter.noLimit()
}
return limiter.allowRequests(120).every("1 minute") as HttpLimiter<any>
})