HAOS Add-on: Ingress-Pfad-Fix im Web UI
Fetches verwendeten absolute Pfade (/api/...) → gingen an HA REST API statt Add-on. Hinter HA Ingress-Proxy muss der Pfad relativ zur Seiten-URL sein. Fix: BASE = window.location.href + "./" → apiUrl() für alle fetch-Aufrufe. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -379,6 +379,10 @@ let currentConfig = {};
|
|||||||
let inverterList = {};
|
let inverterList = {};
|
||||||
let refreshTimer = null;
|
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) {
|
async function fetchJSON(url, opts) {
|
||||||
const r = await fetch(url, opts);
|
const r = await fetch(url, opts);
|
||||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
||||||
@@ -408,7 +412,7 @@ function switchTab(name) {
|
|||||||
// ── Live data ──
|
// ── Live data ──
|
||||||
async function refreshData() {
|
async function refreshData() {
|
||||||
try {
|
try {
|
||||||
const d = await fetchJSON("/api/data");
|
const d = await fetchJSON(apiUrl("api/data"));
|
||||||
updateStatus(d.modbus_ok, d.mqtt_ok);
|
updateStatus(d.modbus_ok, d.mqtt_ok);
|
||||||
updateSubtitle(d);
|
updateSubtitle(d);
|
||||||
updateInfoRow(d);
|
updateInfoRow(d);
|
||||||
@@ -479,7 +483,7 @@ function stopRefresh() {
|
|||||||
// ── Config ──
|
// ── Config ──
|
||||||
async function loadConfig() {
|
async function loadConfig() {
|
||||||
try {
|
try {
|
||||||
currentConfig = await fetchJSON("/api/config");
|
currentConfig = await fetchJSON(apiUrl("api/config"));
|
||||||
fillForm(currentConfig);
|
fillForm(currentConfig);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showToast("Konfiguration konnte nicht geladen werden", "err");
|
showToast("Konfiguration konnte nicht geladen werden", "err");
|
||||||
@@ -488,7 +492,7 @@ async function loadConfig() {
|
|||||||
|
|
||||||
async function loadInverters() {
|
async function loadInverters() {
|
||||||
try {
|
try {
|
||||||
inverterList = await fetchJSON("/api/inverters");
|
inverterList = await fetchJSON(apiUrl("api/inverters"));
|
||||||
buildInverterGrid(inverterList, currentConfig.inverter_model);
|
buildInverterGrid(inverterList, currentConfig.inverter_model);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
@@ -541,7 +545,7 @@ async function saveConfig(e) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetchJSON("/api/config", {
|
await fetchJSON(apiUrl("api/config"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
|
|||||||
Reference in New Issue
Block a user