diff --git a/src/app/config.ts b/src/app/config.ts index 0a878c1f..000101ac 100644 --- a/src/app/config.ts +++ b/src/app/config.ts @@ -165,11 +165,30 @@ export const POSTGRES_SSL_ENABLED = process.env.DISABLE_POSTGRES_SSL === '1' ? false : true; // STORAGE: REDIS -export const REDIS_URL = ( - process.env.KV_URL || + +/** + * Normalizes a Redis URL for use with @upstash/redis. + * + * The SDK requires an HTTPS REST URL, but some providers (e.g. Vercel KV) + * supply a native `rediss://` protocol URL. This converts `rediss://` to + * `https://` by extracting the hostname, so either format works. + */ +const normalizeRedisRestUrl = (url: string | undefined): string | undefined => { + if (!url || !url.startsWith('rediss://')) return url; + try { + return `https://${new URL(url).hostname}`; + } catch { + return url; + } +}; + +// Priority: REST API first (native https://, preferred by @upstash/redis), +// then rediss:// KV_URL (auto-normalized), then custom fallbacks. +export const REDIS_URL = normalizeRedisRestUrl( process.env.KV_REST_API_URL || process.env.EXIF_KV_REST_API_URL || - process.env.UPSTASH_REDIS_REST_URL + process.env.KV_URL || + process.env.UPSTASH_REDIS_REST_URL, ); export const REDIS_TOKEN = ( process.env.KV_TOKEN ||