Update rateLimit.ts

pull/10169/head
zomars 2023-07-14 15:59:04 -07:00
parent 5ff8d2db6e
commit e813f8bb17
1 changed files with 10 additions and 1 deletions

View File

@ -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);
}