fix(agent): use gateway-relative dashboard URL when behind hive-gateway

When the agent page is accessed via hive-gateway (path is /agent/<name>/)
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.
This commit is contained in:
iris 2026-06-05 11:34:26 +02:00 committed by mara
commit defcb5df0b
2 changed files with 15 additions and 2 deletions

View file

@ -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/<name>/`
// 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 */ }
}