Update rateLimit.ts
This commit is contained in:
@@ -32,11 +32,20 @@ export type RatelimitResponse = {
|
||||
pending: Promise<unknown>;
|
||||
};
|
||||
|
||||
let warningDisplayed = false;
|
||||
|
||||
/** Prevent flooding the logs while testing/building */
|
||||
function logOnce(message: string) {
|
||||
if (!warningDisplayed) return;
|
||||
log.warn(message);
|
||||
warningDisplayed = true;
|
||||
}
|
||||
|
||||
export function rateLimiter() {
|
||||
const UPSATCH_ENV_FOUND = process.env.UPSTASH_REDIS_REST_URL && process.env.UPSTASH_REDIS_REST_TOKEN;
|
||||
|
||||
if (!UPSATCH_ENV_FOUND) {
|
||||
log.warn("Disabled due to not finding UPSTASH env variables");
|
||||
logOnce("Disabled due to not finding UPSTASH env variables");
|
||||
return () => ({ success: true, limit: 10, remaining: 999, reset: 0 } as RatelimitResponse);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user