mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-04 23:17:34 +08:00
feat: add /api/new_address ratelimit (#130)
This commit is contained in:
@@ -21,6 +21,13 @@ app.use('/api/*', async (c, next) => {
|
||||
}
|
||||
}
|
||||
if (c.req.path.startsWith("/api/new_address")) {
|
||||
const reqIp = c.req.raw.headers.get("cf-connecting-ip")
|
||||
if (reqIp && c.env.RATE_LIMITER) {
|
||||
const { success } = await c.env.RATE_LIMITER.limit({ key: reqIp })
|
||||
if (!success) {
|
||||
return c.text(`IP=${reqIp} Rate limit exceeded for /api/new_address`, 429)
|
||||
}
|
||||
}
|
||||
await next();
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -24,3 +24,11 @@ BLACK_LIST = ""
|
||||
binding = "DB"
|
||||
database_name = "xxx"
|
||||
database_id = "xxx"
|
||||
|
||||
# ratelimit config for /api/new_address
|
||||
# [[unsafe.bindings]]
|
||||
# name = "RATE_LIMITER"
|
||||
# type = "ratelimit"
|
||||
# namespace_id = "1001"
|
||||
# # 10 requests per minute
|
||||
# simple = { limit = 10, period = 60 }
|
||||
|
||||
Reference in New Issue
Block a user