From f3b3b82c6c161051b2759ec3eced9b3cb4bea66d Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Fri, 10 Apr 2026 19:12:36 -0500 Subject: [PATCH] Improve rate limit config compatibility --- src/app/config.ts | 19 +++++++++++++------ src/platforms/redis.ts | 16 ++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/app/config.ts b/src/app/config.ts index 3a51d429..b48a20f7 100644 --- a/src/app/config.ts +++ b/src/app/config.ts @@ -165,13 +165,20 @@ export const POSTGRES_SSL_ENABLED = process.env.DISABLE_POSTGRES_SSL === '1' ? false : true; // STORAGE: REDIS +export const REDIS_URL = ( + process.env.KV_URL || + process.env.KV_REST_API_URL || + process.env.EXIF_KV_REST_API_URL || + process.env.UPSTASH_REDIS_REST_URL +); +export const REDIS_TOKEN = ( + process.env.KV_TOKEN || + process.env.KV_REST_API_TOKEN || + process.env.EXIF_KV_REST_API_TOKEN || + process.env.UPSTASH_REDIS_REST_TOKEN +); export const HAS_REDIS_STORAGE = - Boolean( - process.env.KV_URL || - process.env.KV_REST_API_URL || - process.env.EXIF_KV_REST_API_URL || - process.env.UPSTASH_REDIS_REST_URL, - ); + Boolean(REDIS_URL && REDIS_TOKEN); // STORAGE: VERCEL BLOB export const HAS_VERCEL_BLOB_STORAGE = diff --git a/src/platforms/redis.ts b/src/platforms/redis.ts index fe411385..252ae45d 100644 --- a/src/platforms/redis.ts +++ b/src/platforms/redis.ts @@ -1,19 +1,11 @@ +import { REDIS_URL, REDIS_TOKEN } from '@/app/config'; import { Redis } from '@upstash/redis'; const KEY_TEST = 'test'; -export const redis = ( - process.env.KV_URL || - process.env.UPSTASH_REDIS_REST_URL -) ? Redis.fromEnv() - : ( - process.env.EXIF_KV_REST_API_URL && - process.env.EXIF_KV_REST_API_TOKEN - ) ? new Redis({ - url: process.env.EXIF_KV_REST_API_URL, - token: process.env.EXIF_KV_REST_API_TOKEN, - }) - : undefined; +export const redis = REDIS_URL && REDIS_TOKEN + ? new Redis({ url: REDIS_URL, token: REDIS_TOKEN }) + : undefined; export const warmRedisConnection = () => { if (redis) { redis.get(KEY_TEST); }