summaryrefslogtreecommitdiff
path: root/web/static/catalog.js
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-12 15:45:52 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:16 -0300
commitfd7775b4e9c24b6bb8f664beb7d4fd2ccecd8d85 (patch)
tree33a4ba949a2c883d3cbd13d7fd069770f013f166 /web/static/catalog.js
parent7f418a6bb3c2d5319d781a61a14aeaf15aff4c89 (diff)
downloadcloud9-fd7775b4e9c24b6bb8f664beb7d4fd2ccecd8d85.tar.gz
cloud9-fd7775b4e9c24b6bb8f664beb7d4fd2ccecd8d85.zip
9web: serve local sites with 9P build controls and passive listener discovery
Add optional catalogue mode with an explicit site registry, per-site HTTP roots, MIME/index/pretty-URL handling, HEAD and byte ranges. Existing generated sites are available immediately, without preview processes. Expose build, watch, cancel, status, logs and state events through the shared 9P backend and HTTP dashboard. Supervise process groups, coalesce queued rebuilds and watch configured source paths. Discover Linux TCP listeners by socket inode ownership and executable/argument recognizers; never probe endpoints. Document configuration, the user-systemd unit, workstation ports, network access assumptions and limitations including in-place publication and static-only Worker sites. Keep the original upstream gateway mode. Validation: catalogue integration suite (including paginated directory reads, cancellation and parked events), existing HTTP filesystem and mux suites, real 9ns mount, dual-stack service restart and all five workstation sites. Real entomology build: 129 pages, zero failures.
Diffstat (limited to 'web/static/catalog.js')
-rw-r--r--web/static/catalog.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/web/static/catalog.js b/web/static/catalog.js
new file mode 100644
index 0000000..f868a16
--- /dev/null
+++ b/web/static/catalog.js
@@ -0,0 +1,56 @@
+const $ = id => document.getElementById(id);
+let activeLog = null;
+const element = (tag, text) => { const e = document.createElement(tag); e.textContent = text; return e; };
+function url(address, port, protocol = 'http') {
+ let host = address;
+ if (!host || host === '0.0.0.0' || host === '::') host = location.hostname;
+ host = host.replace(/^\[|\]$/g, '');
+ return `${protocol}://${host.includes(':') ? `[${host}]` : host}:${port}/`;
+}
+async function control(name, command) {
+ try {
+ const r = await fetch(`/_cloud9/sites/${encodeURIComponent(name)}/ctl`, { method:'POST', headers:{'Content-Type':'text/plain'}, body:command });
+ if (!r.ok) throw new Error(await r.text());
+ $('message').textContent = `${name}: ${command} requested`;
+ await refresh();
+ } catch (e) { $('message').textContent = e.message; }
+}
+function button(text, action, disabled = false) { const b = element('button', text); b.disabled = disabled; b.onclick = action; return b; }
+function listenerRow(item) {
+ const tr = element('tr', '');
+ const name = element('td', '');
+ if (item.protocol !== 'unknown') {
+ const a = element('a', item.service); a.href = url(item.address, item.port, item.protocol); name.append(a);
+ } else name.textContent = item.process || 'Unknown';
+ tr.append(name, element('td', `${item.address}:${item.port}${item.local ? ' · local only' : ''}`));
+ const process = element('td', item.pid ? `PID ${item.pid}` : 'Unavailable'); process.className = 'process'; tr.append(process, element('td', item.evidence));
+ return tr;
+}
+async function refresh() {
+ try {
+ const r = await fetch('/_cloud9/catalog.json'); if (!r.ok) throw new Error(`Dashboard: ${r.status}`);
+ const data = await r.json();
+ $('sites').replaceChildren();
+ for (const site of data.sites) {
+ const card = element('article', ''); const h = element('h2', ''); const a = element('a', site.title); a.href = url('', site.port); h.append(a);
+ const s = site.status;
+ card.append(h, element('code', site.root), element('p', `${s.phase}${s.watching ? ' · watch on' : ''}${s.queued ? ' · build queued' : ''}${s.exit_code !== null ? ` · exit ${s.exit_code}` : ''}`));
+ if (s.finished) card.append(element('small', `Last finished ${new Date(s.finished * 1000).toLocaleString()}`), element('br', ''));
+ card.append(button('Build', () => control(site.name, 'build'), !site.build), button(s.watching ? 'Stop watching' : 'Watch', () => control(site.name, s.watching ? 'watch off' : 'watch on'), !site.watch), button('Cancel', () => control(site.name, 'cancel'), !s.pid && !s.queued), button('Log', () => { activeLog = site.name; $('log-title').textContent = site.title; $('logs').showModal(); refreshLog(); }));
+ $('sites').append(card);
+ }
+ const known = data.listeners.filter(x => x.protocol !== 'unknown');
+ const unknown = data.listeners.filter(x => x.protocol === 'unknown');
+ $('services').replaceChildren(...known.map(listenerRow));
+ $('unknown').replaceChildren(...unknown.map(listenerRow));
+ $('unknown-title').textContent = `Other listeners (${unknown.length})`;
+ if (data.discovery_error) $('message').textContent = data.discovery_error;
+ } catch (e) { $('message').textContent = e.message; }
+}
+async function refreshLog() {
+ if (!activeLog) return;
+ try { const r = await fetch(`/fs/sites/${encodeURIComponent(activeLog)}/log`); $('log-text').textContent = await r.text(); } catch (e) { $('log-text').textContent = e.message; }
+}
+$('close-log').onclick = () => { activeLog = null; $('logs').close(); };
+$('logs').onclose = () => { activeLog = null; };
+refresh(); setInterval(refresh, 5000); setInterval(refreshLog, 1500);