fix: always fetch live API data in server mode#92
Conversation
When running in Docker/Kubernetes, the dashboard serves baked-in data from the Docker image build time instead of fetching live data from the API. This is because the DOMContentLoaded handler checks `canProbeApi && !hasInlineData` — but the inline data `D` variable is always populated from the build, so `hasInlineData` is always true and the API fetch is never executed. The fix changes the condition to just `canProbeApi`, so the dashboard always fetches from `/api/data` when running on a server (HTTP/HTTPS), regardless of whether inline data exists. File mode (opened as a local file) still uses inline data as a fallback. This caused the dashboard to show data from whenever the Docker image was built, not live intelligence data.
|
Good fix. We ("we" = me and my agent) hit this exact issue in production. Serving Crucix behind a Cloudflare tunnel at https://intel.zerotomonero.xyz, the dashboard showed stale build-time data indefinitely because SSE couldn't reach the browser, and the inline We applied a complementary server-side patch to // After broadcast({ type: 'update', data: currentData });
try {
const htmlPath = join(ROOT, 'dashboard/public/jarvis.html');
let html = readFileSync(htmlPath, 'utf-8');
const json = JSON.stringify(currentData);
html = html.replace(/^(let|const) D = .*;\s*$/m, () => 'let D = ' + json + ';');
writeFileSync(htmlPath, html);
console.log('[Crucix] jarvis.html updated with fresh sweep data');
} catch (err) {
console.error('[Crucix] Failed to update jarvis.html:', err.message);
}The two approaches are complementary:
Worth noting: this server-side write also means Happy to open a separate PR for the server-side patch if there's interest. |
|
The issue looks valid: in server mode, baked inline I would not approve this exact patch yet because the new path should validate the API response before replacing inline data. As written, if Suggested shape: fetch('/api/data')
.then(r => {
if (!r.ok) throw new Error(`API ${r.status}`);
return r.json();
})
.then(data => {
if (!data?.meta) throw new Error('Invalid API data');
D = data;
init();
connectSSE();
})
.catch(() => {
if (D && D.meta) { init(); connectSSE(); }
});Checks I ran against the simulated merge onto current
So: valid bug, small fix needed before approval. |
Problem
When running Crucix in Docker/Kubernetes, the dashboard shows stale data from the Docker image build time instead of live intelligence data.
The
DOMContentLoadedhandler injarvis.htmlchecks:But the inline data variable
Dis always populated at build time (line 375), sohasInlineDatais alwaystrueand the/api/datafetch is never executed. The dashboard renders the baked-in snapshot forever.Fix
Change the condition to just
canProbeApi:This makes the dashboard always fetch from
/api/datawhen running on a server (HTTP/HTTPS). File mode (local HTML file) still uses inline data as fallback sincecanProbeApiisfalseforfile://protocol.Impact
connectSSE()call in the fetch handler ensures live updates continue after initial load🤖 Generated with Claude Code