import { KNOWN_HOSTS, DEFAULT_HOST } from '../config.js'; // Detect server address from the URL export function detectServerAddress() { let host = DEFAULT_HOST; if (typeof window.location == 'object') { if (window.location.protocol == 'file:') { // No real page origin to derive a host/port from at all (e.g. a file:// build opened // directly) -- this is the one case KNOWN_HOSTS.local's hardcoded port is actually needed. host = KNOWN_HOSTS.local; } else if (window.location.hostname) { // Was `hostname == 'localhost'` on its own branch returning the hardcoded KNOWN_HOSTS.local // ('localhost:6060') unconditionally -- any local/self-hosted deployment or dev proxy not on // port 6060 (this project's own dev-proxy runs on 8093) got a wrong host and every "no // cached tenant/host info yet" connection attempt (e.g. right after clearing storage) failed // outright before a later reconnect could recover with the right address. Same-origin // same-port assumption already used for every non-localhost host applies here too. host = window.location.hostname + (window.location.port ? ':' + window.location.port : ''); } } return host; } // Detect if the page is served over HTTPS. export function isSecureConnection() { if (typeof window.location == 'object') { return window.location.protocol == 'https:'; } return false; } export function isLocalHost() { if (typeof window.location == 'object') { return window.location.hostname == 'localhost'; } return false; }