Update rateLimit.ts
parent
5ff8d2db6e
commit
e813f8bb17
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue