From defcb5df0b53065314d7788b1701b89804d48335 Mon Sep 17 00:00:00 2001 From: iris Date: Fri, 5 Jun 2026 11:34:26 +0200 Subject: [PATCH] fix(agent): use gateway-relative dashboard URL when behind hive-gateway When the agent page is accessed via hive-gateway (path is /agent//) the dashboard lives at the same origin's root (/), not at the direct TCP port. Both app.js (overflow menu / setHeader) and stats.js (dashboard-link anchor) previously hardcoded http://hostname:port which is wrong or unreachable behind HTTPS TLS termination. Detection: if location.pathname starts with '/agent/', use location.origin + '/' as the dashboard base. Otherwise fall back to the original direct-TCP construction for non-gateway deploys. --- frontend/packages/agent/src/app.js | 9 ++++++++- frontend/packages/agent/src/stats.js | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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 */ } }