type ObjectType = T extends string ? string : T extends boolean ? boolean : never export function config(env_var: string, default_value: T): ObjectType { const srv_url = getDynamicSrvUrl(env_var) if (srv_url) { return srv_url as ObjectType } const connector = (window.location.host.includes('adopus.no') && 'adopus') || (window.location.host.includes('adcuris.no') && 'adcuris') || undefined if (connector) { return (window._env_cloud?.[connector]?.[env_var] ?? default_value) as ObjectType } return window.__ENV?.[env_var] as ObjectType } export function configWeb(env_var: string, default_value: T): ObjectType { const srv_url = getDynamicSrvUrl(env_var) if (srv_url) { return srv_url as ObjectType } return (window.__ENV?.[env_var] ?? default_value) as ObjectType } function getDynamicSrvUrl(env_var: string) { if (env_var.startsWith('SRV')) { const env_name = env_var.replace('SRV_', '').toLowerCase() const srv_url = window._srvUrls?.[env_name] if (srv_url) { return srv_url } } return } export function httpToWs(url: string) { return url.replace('http', 'ws').replace('https', 'wss') } export function httpToWs2(url: string) { url = absoluteUrl(url) return url.replace('http', 'ws').replace('https', 'wss') } const is_localhost = window.location.origin.includes('local') || window.location.origin.includes('172.17.0.1') function absoluteUrl(url: string) { if (!is_localhost) { url = window.location.origin + url } return url }