fix(app): add normalize func for redis url (#391)
- solves issue when providers use rediss:// instead of https://
This commit is contained in:
parent
d7305de268
commit
175970252c
@ -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 ||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user