fix: resolve internal kong url to configurable public supabase url
All checks were successful
Staging Build / build (push) Successful in 3m30s
All checks were successful
Staging Build / build (push) Successful in 3m30s
This commit is contained in:
@@ -14,16 +14,31 @@ export const hasEnvVars =
|
|||||||
|
|
||||||
export function resolveSupabaseUrl(url: string | undefined): string | undefined {
|
export function resolveSupabaseUrl(url: string | undefined): string | undefined {
|
||||||
if (!url) return url;
|
if (!url) return url;
|
||||||
|
|
||||||
|
// Bestimme die externe Basis-URL aus Umgebungsvariablen (falls vorhanden und extern)
|
||||||
|
let extBase = process.env.NEXT_PUBLIC_SUPABASE_URL_EXTERNAL || process.env.NEXT_PUBLIC_SUPABASE_URL || '';
|
||||||
|
if (extBase.includes('kong') || extBase.includes('supabase-kong')) {
|
||||||
|
extBase = ''; // ignorieren, da intern
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
try {
|
try {
|
||||||
const parsed = new URL(url);
|
const parsed = new URL(url);
|
||||||
if (parsed.hostname === 'supabase-kong' || parsed.hostname === 'kong') {
|
if (parsed.hostname === 'supabase-kong' || parsed.hostname === 'kong') {
|
||||||
parsed.hostname = window.location.hostname;
|
if (extBase) {
|
||||||
parsed.protocol = window.location.protocol;
|
const extUrl = new URL(extBase);
|
||||||
if (window.location.hostname === 'localhost' && parsed.port === '8000') {
|
parsed.hostname = extUrl.hostname;
|
||||||
parsed.port = '8000';
|
parsed.port = extUrl.port;
|
||||||
|
parsed.protocol = extUrl.protocol;
|
||||||
} else {
|
} else {
|
||||||
parsed.port = ''; // Port entfernen für Produktion hinter Reverse Proxy
|
// Fallback auf die aktuelle Browser-Domain
|
||||||
|
parsed.hostname = window.location.hostname;
|
||||||
|
parsed.protocol = window.location.protocol;
|
||||||
|
if (window.location.hostname === 'localhost' && parsed.port === '8000') {
|
||||||
|
parsed.port = '8000';
|
||||||
|
} else {
|
||||||
|
parsed.port = ''; // Port entfernen für Produktion hinter Reverse Proxy
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return parsed.toString().replace(/\/$/, '');
|
return parsed.toString().replace(/\/$/, '');
|
||||||
}
|
}
|
||||||
@@ -34,11 +49,21 @@ export function resolveSupabaseUrl(url: string | undefined): string | undefined
|
|||||||
return parsed.toString().replace(/\/$/, '');
|
return parsed.toString().replace(/\/$/, '');
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
let resolved = url
|
let resolved = url;
|
||||||
.replace('//supabase-kong:8000', `//${window.location.hostname}`)
|
if (extBase) {
|
||||||
.replace('//kong:8000', `//${window.location.hostname}`)
|
const extUrl = new URL(extBase);
|
||||||
.replace('//supabase-kong', `//${window.location.hostname}`)
|
resolved = resolved
|
||||||
.replace('//kong', `//${window.location.hostname}`);
|
.replace('//supabase-kong:8000', `//${extUrl.host}`)
|
||||||
|
.replace('//kong:8000', `//${extUrl.host}`)
|
||||||
|
.replace('//supabase-kong', `//${extUrl.host}`)
|
||||||
|
.replace('//kong', `//${extUrl.host}`);
|
||||||
|
} else {
|
||||||
|
resolved = resolved
|
||||||
|
.replace('//supabase-kong:8000', `//${window.location.hostname}`)
|
||||||
|
.replace('//kong:8000', `//${window.location.hostname}`)
|
||||||
|
.replace('//supabase-kong', `//${window.location.hostname}`)
|
||||||
|
.replace('//kong', `//${window.location.hostname}`);
|
||||||
|
}
|
||||||
if (window.location.protocol === 'https:') {
|
if (window.location.protocol === 'https:') {
|
||||||
resolved = resolved.replace('http://', 'https://');
|
resolved = resolved.replace('http://', 'https://');
|
||||||
}
|
}
|
||||||
@@ -49,20 +74,15 @@ export function resolveSupabaseUrl(url: string | undefined): string | undefined
|
|||||||
try {
|
try {
|
||||||
const parsed = new URL(url);
|
const parsed = new URL(url);
|
||||||
if (parsed.hostname === 'supabase-kong' || parsed.hostname === 'kong') {
|
if (parsed.hostname === 'supabase-kong' || parsed.hostname === 'kong') {
|
||||||
if (process.env.NEXT_PUBLIC_SUPABASE_URL_EXTERNAL) {
|
const ext = extBase || 'http://localhost:8000';
|
||||||
const extUrl = new URL(process.env.NEXT_PUBLIC_SUPABASE_URL_EXTERNAL);
|
const extUrl = new URL(ext);
|
||||||
parsed.hostname = extUrl.hostname;
|
parsed.hostname = extUrl.hostname;
|
||||||
parsed.port = extUrl.port;
|
parsed.port = extUrl.port;
|
||||||
parsed.protocol = extUrl.protocol;
|
parsed.protocol = extUrl.protocol;
|
||||||
} else {
|
|
||||||
parsed.hostname = 'localhost';
|
|
||||||
parsed.port = '8000';
|
|
||||||
parsed.protocol = 'http:';
|
|
||||||
}
|
|
||||||
return parsed.toString().replace(/\/$/, '');
|
return parsed.toString().replace(/\/$/, '');
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
const target = process.env.NEXT_PUBLIC_SUPABASE_URL_EXTERNAL || 'http://localhost:8000';
|
const target = extBase || 'http://localhost:8000';
|
||||||
const targetUrl = new URL(target);
|
const targetUrl = new URL(target);
|
||||||
return url
|
return url
|
||||||
.replace('//supabase-kong:8000', `//${targetUrl.host}`)
|
.replace('//supabase-kong:8000', `//${targetUrl.host}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user