fix(app): add normalize func for redis url (#391)

- solves issue when providers use rediss:// instead of https://
This commit is contained in:
João Pedro Sconetto 2026-05-09 17:48:28 -03:00 committed by GitHub
parent d7305de268
commit 175970252c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -165,11 +165,30 @@ export const POSTGRES_SSL_ENABLED =
process.env.DISABLE_POSTGRES_SSL === '1' ? false : true; process.env.DISABLE_POSTGRES_SSL === '1' ? false : true;
// STORAGE: REDIS // 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.KV_REST_API_URL ||
process.env.EXIF_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 = ( export const REDIS_TOKEN = (
process.env.KV_TOKEN || process.env.KV_TOKEN ||