Add free tier rate limiting with Upstash Redis and API key handling

This commit is contained in:
Riccardo Giorato
2025-12-25 16:04:00 +01:00
parent d5b163e586
commit 79bd750630
14 changed files with 571 additions and 74 deletions
+15
View File
@@ -0,0 +1,15 @@
import { Ratelimit } from "@upstash/ratelimit"
import { Redis } from "@upstash/redis"
const redis = new Redis({
url: process.env.UPSTASH_REDIS_REST_URL!,
token: process.env.UPSTASH_REDIS_REST_TOKEN!,
})
// Free tier: 1 comic per week (fixed window)
export const freeTierRateLimit = new Ratelimit({
redis,
limiter: Ratelimit.fixedWindow(1, "7 d"),
analytics: true,
prefix: "ratelimit:free-comics",
})