feat(api): ratelimiting

This commit is contained in:
taskylizard 2025-01-01 11:25:05 +00:00
parent 26213d9f91
commit 1148023b1a
No known key found for this signature in database
GPG key ID: 1820131ED1A24120
10 changed files with 139 additions and 150 deletions

View file

@ -0,0 +1,17 @@
export default defineEventHandler(async (event) => {
const { cloudflare } = event.context
// FIXME: THIS IS NOT RECOMMENDED. BUT I WILL USE IT FOR NOW
// Not recommended: many users may share a single IP, especially on mobile networks
// or when using privacy-enabling proxies
const ipAddress = getHeader(event, 'CF-Connecting-IP') ?? ''
const { success } = await // KILL YOURSELF
(cloudflare.env as unknown as Env).RATE_LIMITER.limit({
key: ipAddress
})
if (!success) {
throw createError('Failure global rate limit exceeded')
}
})