This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
wikipedia-game-solver/apps/api/src/start/limiter.ts

17 lines
603 B
TypeScript
Raw Normal View History

2024-08-12 15:13:24 +02:00
/**
* 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.
*/
2024-08-12 19:19:43 +02:00
import { APP_KEY, APP_KEY_HEADER_NAME } from "#config/app.js"
2024-08-12 15:13:24 +02:00
import app from "@adonisjs/core/services/app"
import limiter from "@adonisjs/limiter/services/main"
2024-08-12 19:19:43 +02:00
export const throttle = limiter.define("global", (context) => {
if (app.inTest || context.request.header(APP_KEY_HEADER_NAME) === APP_KEY) {
2024-08-12 15:13:24 +02:00
return limiter.noLimit()
}
return limiter.allowRequests(120).every("1 minute")
})