diff --git a/haos-addon/src/web/index.html b/haos-addon/src/web/index.html index 4f10bc5..16aa457 100644 --- a/haos-addon/src/web/index.html +++ b/haos-addon/src/web/index.html @@ -379,6 +379,10 @@ let currentConfig = {}; let inverterList = {}; let refreshTimer = null; +// Basis-URL relativ zur aktuellen Seite (funktioniert hinter HA Ingress-Proxy) +const BASE = new URL("./", window.location.href).pathname; +function apiUrl(path) { return BASE + path; } + async function fetchJSON(url, opts) { const r = await fetch(url, opts); if (!r.ok) throw new Error(`HTTP ${r.status}`); @@ -408,7 +412,7 @@ function switchTab(name) { // ── Live data ── async function refreshData() { try { - const d = await fetchJSON("/api/data"); + const d = await fetchJSON(apiUrl("api/data")); updateStatus(d.modbus_ok, d.mqtt_ok); updateSubtitle(d); updateInfoRow(d); @@ -479,7 +483,7 @@ function stopRefresh() { // ── Config ── async function loadConfig() { try { - currentConfig = await fetchJSON("/api/config"); + currentConfig = await fetchJSON(apiUrl("api/config")); fillForm(currentConfig); } catch (e) { showToast("Konfiguration konnte nicht geladen werden", "err"); @@ -488,7 +492,7 @@ async function loadConfig() { async function loadInverters() { try { - inverterList = await fetchJSON("/api/inverters"); + inverterList = await fetchJSON(apiUrl("api/inverters")); buildInverterGrid(inverterList, currentConfig.inverter_model); } catch (e) {} } @@ -541,7 +545,7 @@ async function saveConfig(e) { }; try { - await fetchJSON("/api/config", { + await fetchJSON(apiUrl("api/config"), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),