agent UI: relative paths for all assets/api/ws so the page works under any nginx prefix (#14)
Per mara on #14: 'make agent page not assume root path, links / api calls need to be relative'. atlas's nginx side (#15) will mount the per-agent UI at a prefix like /agent/<name>/ instead of its own port; for the page to keep working under that prefix, every in-page reference needs to resolve document-relative rather than root-anchored. Converted in this pass: - HTML <link>/<script>/<img>/<a> hrefs in index.html, stats.html, screen.html: '/icon' → 'icon', '/static/agent.css' → 'static/agent.css', back links '/' → './'. - app.js fetch() targets ('/api/state' → 'api/state', /api/cancel, /api/loose-ends, etc.), form actions ('/login/start', '/send'), EventSource urls ('/events/stream', '/events/history'). - stats.js fetch() targets. - screen.html WebSocket URL: was hardcoded as ws(s)://host/screen/ws; now derived from document.baseURI via new URL('screen/ws', document.baseURI) so the gateway prefix flows through. Slash-command labels (/cancel, /compact, …) and the dashboard-port link (different port, intentionally absolute) intentionally untouched. Added a new 'Per-agent relative paths' section to docs/web-ui.md covering the rationale + the trailing-slash gotcha (sub-pages like /stats must NOT have a trailing slash, or 'static/app.js' resolves under /stats/ instead of replacing the segment). Functional code unchanged; build clean. Damocles + atlas can proceed with the backend / nginx side without depending on this landing first, but once both ship the agent page works under the gateway-prefixed URL without further changes. refs #14
This commit is contained in:
parent
003b36c4a0
commit
37d99ed118
6 changed files with 70 additions and 27 deletions
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>screen</title>
|
||||
<link rel="icon" type="image/svg+xml" href="/icon">
|
||||
<link rel="icon" type="image/svg+xml" href="icon">
|
||||
<style>
|
||||
/* Catppuccin Mocha palette (mirrors base.css) */
|
||||
:root {
|
||||
|
|
@ -82,7 +82,7 @@ canvas { display: block; cursor: default; }
|
|||
<body>
|
||||
<div id="toolbar">
|
||||
<strong>🖥 screen</strong>
|
||||
<a href="/" title="back to agent page">← agent</a>
|
||||
<a href="./" title="back to agent page">← agent</a>
|
||||
<button id="fit-toggle" class="tbtn" title="Toggle fit-to-window scaling">⤢ fit</button>
|
||||
<button id="match-toggle" class="tbtn" title="Resize the remote desktop to fit this window" disabled>⤡ match size</button>
|
||||
<button id="debug-toggle" class="tbtn" title="Toggle RFB debug log">debug</button>
|
||||
|
|
@ -206,8 +206,14 @@ canvas { display: block; cursor: default; }
|
|||
}
|
||||
|
||||
// --- WebSocket connection ---
|
||||
// Path-relative so the agent page mounted under a prefix
|
||||
// (e.g. /agent/<name>/screen via nginx, #14) still hits the right
|
||||
// upstream. `document.baseURI` resolves against the page's URL;
|
||||
// swapping protocol on top gives ws(s)://host/<prefix>/screen/ws.
|
||||
const proto = location.protocol === 'https:' ? 'wss' : 'ws';
|
||||
const ws = new WebSocket(`${proto}://${location.host}/screen/ws`);
|
||||
const wsUrl = new URL('screen/ws', document.baseURI);
|
||||
wsUrl.protocol = proto + ':';
|
||||
const ws = new WebSocket(wsUrl.toString());
|
||||
ws.binaryType = 'arraybuffer';
|
||||
|
||||
ws.onopen = () => { dbg('WebSocket open — starting RFB handshake', 'ok'); setStatus('handshaking…'); };
|
||||
|
|
|
|||
Loading…
Reference in a new issue