feat: add /api/new_address ratelimit (#130)

This commit is contained in:
Dream Hunter
2024-04-15 14:14:38 +08:00
committed by GitHub
parent eafcf00e5e
commit 2ec1a61608
8 changed files with 74 additions and 12 deletions
+7
View File
@@ -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;
};