From ada15ac7778f47c923dbfd42f0da9905f14deb34 Mon Sep 17 00:00:00 2001 From: Michael Chus Date: Sun, 29 Mar 2026 10:31:46 +0300 Subject: [PATCH] fix: loading screen via Go handler instead of file:// HTML MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - bee-web.service: remove After=bee-audit so Go starts immediately - Go serves loading page from / when audit JSON not yet present; JS polls /api/ready (503 until file exists, 200 when ready) then redirects to dashboard - bee-openbox-session: wait for /healthz (Go binds fast <2s), open http://localhost/ directly — no file:// cross-origin issues - Remove loading.html static file Co-Authored-By: Claude Sonnet 4.6 --- audit/internal/webui/server.go | 58 +++++++++++++ .../etc/systemd/system/bee-web.service | 2 +- iso/overlay/usr/local/bin/bee-openbox-session | 9 +- iso/overlay/usr/local/share/bee/loading.html | 82 ------------------- 4 files changed, 67 insertions(+), 84 deletions(-) delete mode 100644 iso/overlay/usr/local/share/bee/loading.html diff --git a/audit/internal/webui/server.go b/audit/internal/webui/server.go index 5739993..c9461c8 100644 --- a/audit/internal/webui/server.go +++ b/audit/internal/webui/server.go @@ -163,6 +163,7 @@ func NewHandler(opts HandlerOptions) http.Handler { // ── Infrastructure ────────────────────────────────────────────────────── mux.HandleFunc("GET /healthz", h.handleHealthz) + mux.HandleFunc("GET /api/ready", h.handleReady) // ── Existing read-only endpoints (preserved for compatibility) ────────── mux.HandleFunc("GET /audit.json", h.handleAuditJSON) @@ -654,9 +655,66 @@ func sparseLabels(labels []string, n int) []string { // ── Page handler ───────────────────────────────────────────────────────────── +func (h *handler) handleReady(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Cache-Control", "no-store") + if _, err := os.Stat(h.opts.AuditPath); err != nil { + w.WriteHeader(http.StatusServiceUnavailable) + _, _ = w.Write([]byte("starting")) + return + } + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte("ready")) +} + +const loadingPageHTML = ` + + + +EASY-BEE + + + +
+ +
+
Starting up...
+
+ + +` + func (h *handler) handlePage(w http.ResponseWriter, r *http.Request) { page := strings.TrimPrefix(r.URL.Path, "/") if page == "" { + // Serve loading page until audit snapshot exists + if _, err := os.Stat(h.opts.AuditPath); err != nil { + w.Header().Set("Cache-Control", "no-store") + w.Header().Set("Content-Type", "text/html; charset=utf-8") + _, _ = w.Write([]byte(loadingPageHTML)) + return + } page = "dashboard" } // Redirect old routes to new names diff --git a/iso/overlay/etc/systemd/system/bee-web.service b/iso/overlay/etc/systemd/system/bee-web.service index 15745df..632b2d3 100644 --- a/iso/overlay/etc/systemd/system/bee-web.service +++ b/iso/overlay/etc/systemd/system/bee-web.service @@ -1,6 +1,6 @@ [Unit] Description=Bee: hardware audit web viewer -After=bee-network.service bee-audit.service +After=bee-network.service Wants=bee-audit.service [Service] diff --git a/iso/overlay/usr/local/bin/bee-openbox-session b/iso/overlay/usr/local/bin/bee-openbox-session index 9f20f23..55a11b1 100755 --- a/iso/overlay/usr/local/bin/bee-openbox-session +++ b/iso/overlay/usr/local/bin/bee-openbox-session @@ -8,6 +8,13 @@ xset -dpms xset s noblank tint2 & +# Wait for bee-web to bind (Go starts fast, usually <2s) +i=0 +while [ $i -lt 30 ]; do + if curl -sf http://localhost/healthz >/dev/null 2>&1; then break; fi + sleep 1 + i=$((i+1)) +done chromium \ --disable-infobars \ --disable-translate \ @@ -15,6 +22,6 @@ chromium \ --disable-session-crashed-bubble \ --disable-features=TranslateUI \ --start-fullscreen \ - file:///usr/local/share/bee/loading.html & + http://localhost/ & exec openbox diff --git a/iso/overlay/usr/local/share/bee/loading.html b/iso/overlay/usr/local/share/bee/loading.html deleted file mode 100644 index a633865..0000000 --- a/iso/overlay/usr/local/share/bee/loading.html +++ /dev/null @@ -1,82 +0,0 @@ - - - - -EASY-BEE - - - -
- -
-
Starting
-
- - -