mirror of
https://github.com/fmhy/edit.git
synced 2026-03-11 08:55:38 +00:00
18 lines
568 B
TypeScript
18 lines
568 B
TypeScript
|
|
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')
|
|||
|
|
}
|
|||
|
|
})
|