env vars
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { assertKvConfiguredInProduction, isKvConfigured, isProductionEnvironment } from './config/env';
|
||||
|
||||
const RATE_LIMIT_WINDOW = 60 * 60 * 1000; // 1 hour in milliseconds
|
||||
const MAX_REQUESTS_PER_WINDOW = 5;
|
||||
const RATE_LIMIT_PREFIX = 'ratelimit:signup:';
|
||||
|
||||
const isDev = !process.env.KV_REST_API_URL;
|
||||
// Dev fallback: only allowed outside production.
|
||||
const isDev = !isProductionEnvironment() && !isKvConfigured();
|
||||
|
||||
// In-memory fallback for development
|
||||
const devRateLimits = new Map<string, { count: number; resetAt: number }>();
|
||||
@@ -49,6 +52,8 @@ export async function checkRateLimit(identifier: string): Promise<{
|
||||
}
|
||||
|
||||
// Production: Use Vercel KV
|
||||
assertKvConfiguredInProduction();
|
||||
|
||||
const { kv } = await import('@vercel/kv');
|
||||
const key = `${RATE_LIMIT_PREFIX}${identifier}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user