const API_BASE = "http://127.0.0.1:8080"; function getApiBase() { return API_BASE; } function apiURL(path) { const base = getApiBase(); if (!base) return path; return base + path; } function wsURL(path) { const base = getApiBase(); if (base) { let u; try { u = new URL(base); } catch (e) { return null; } u.protocol = u.protocol === "https:" ? "wss:" : "ws:"; u.pathname = u.pathname.replace(/\/+$/, "") + path; return u.toString(); } const proto = location.protocol === "https:" ? "wss:" : "ws:"; return `${proto}//${location.host}${path}`; }