feat(api): ratelimiting

because some group of idiots like me so much that they spam my endpoint
This commit is contained in:
taskylizard
2024-07-10 03:47:04 +00:00
parent 9e91f608b9
commit a69a834899
4 changed files with 44 additions and 7 deletions

View File

@@ -7,6 +7,14 @@ export default defineEventHandler(async (event) => {
FeedbackSchema.parseAsync
)
const env = useRuntimeConfig(event)
const { pathname } = new URL(event.node.req.url)
const { success } = await env.MY_RATE_LIMITER.limit({ key: pathname })
if (!success) {
return new Response(`429 Failure rate limit exceeded for ${pathname}`, {
status: 429
})
}
let description = `${message}\n\n`
if (page) description += `**Page:** \`${page}\``