Files
carmanagement/apps/admin/src/lib/appUrls.ts
T
2026-05-17 08:53:19 -04:00

29 lines
823 B
TypeScript

export function resolveBrowserAppUrl(fallback: string): string {
if (typeof window === 'undefined') return fallback
const h = window.location.hostname
if (h === 'localhost' || h === '127.0.0.1') return fallback.replace(/\/$/, '')
try {
const target = new URL(fallback)
target.protocol = window.location.protocol
target.hostname = h
target.port = ''
return target.toString().replace(/\/$/, '')
} catch {
return fallback
}
}
export function resolveServerAppUrl(fallback: string, host: string | null, proto?: string | null): string {
if (!host) return fallback
try {
const target = new URL(fallback)
target.protocol = `${proto || target.protocol.replace(':', '')}:`
target.host = host
return target.toString().replace(/\/$/, '')
} catch {
return fallback
}
}