diff --git a/frontend/packages/agent/src/app.js b/frontend/packages/agent/src/app.js index feedcce7..b9320108 100644 --- a/frontend/packages/agent/src/app.js +++ b/frontend/packages/agent/src/app.js @@ -155,7 +155,14 @@ window.marked = marked; const hiveLabel = hiveName || null; const tab = qualifiedLabel && qualifiedLabel !== label ? qualifiedLabel : label; document.title = hiveLabel ? `${label} // ${hiveLabel}` : `${tab} // hyperhive`; - const dashUrl = `${location.protocol}//${location.hostname}:${dashboardPort}/`; + // When accessed via hive-gateway the page lives at + // `/agent//` on the same origin as the dashboard (`/`). + // Detect this by the path prefix and use `location.origin` instead + // of the direct TCP port โ€” the direct port is unreachable or + // wrong scheme behind HTTPS TLS termination. + const dashUrl = location.pathname.startsWith('/agent/') + ? location.origin + '/' + : `${location.protocol}//${location.hostname}:${dashboardPort}/`; dashboardBase = dashUrl; populateOverflowMenu(label, dashUrl); // Swarm label in the chrome: show "swarm/hive" when both set, just diff --git a/frontend/packages/agent/src/stats.js b/frontend/packages/agent/src/stats.js index 0565cf5d..5769390e 100644 --- a/frontend/packages/agent/src/stats.js +++ b/frontend/packages/agent/src/stats.js @@ -330,7 +330,13 @@ window.Chart = Chart; document.title = 'stats ยท ' + s.label; document.getElementById('title').textContent = 'โ—† ' + s.label + ' โ—†'; const dl = document.getElementById('dashboard-link'); - dl.href = 'http://' + window.location.hostname + ':' + s.dashboard_port + '/'; + // When accessed via hive-gateway the page lives at `/agent//` + // on the same origin as the dashboard (`/`). Detect via path prefix + // rather than the direct port (which is unreachable or wrong scheme + // behind HTTPS TLS termination). + dl.href = window.location.pathname.startsWith('/agent/') + ? window.location.origin + '/' + : 'http://' + window.location.hostname + ':' + s.dashboard_port + '/'; } catch (_) { /* non-fatal */ } }