From 6aedbe121a56a0562d3352c3bd343aae7b392bc0 Mon Sep 17 00:00:00 2001 From: Benson Wong Date: Mon, 3 Nov 2025 22:37:06 -0500 Subject: [PATCH] cmd/wol-proxy: show a loading page for / (#381) When requesting / wol-proxy will show a loading page that polls /status every second. When the upstream server is ready the loading page will refresh causing the actual root page to be displayed --- CLAUDE.md | 2 +- cmd/wol-proxy/index.html | 64 ++++++++++++++++++++++++++++++++++++++ cmd/wol-proxy/wol-proxy.go | 13 ++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 cmd/wol-proxy/index.html diff --git a/CLAUDE.md b/CLAUDE.md index a271fd0..c6953f3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -11,7 +11,7 @@ llama-swap is a light weight, transparent proxy server that provides automatic m ## Testing -- `make test-dev` - Use this when making iterative changes. Runs `go test` and `staticcheck`. Fix any static checking errors. +- `make test-dev` - Use this when making iterative changes. Runs `go test` and `staticcheck`. Fix any static checking errors. Use this only when changes are made to any code under the `proxy/` directory - `make test-all` - runs at the end before completing work. Includes long running concurrency tests. ## Workflow Tasks diff --git a/cmd/wol-proxy/index.html b/cmd/wol-proxy/index.html new file mode 100644 index 0000000..3bbf9be --- /dev/null +++ b/cmd/wol-proxy/index.html @@ -0,0 +1,64 @@ + + + + +Loading... + + + +
+

Waking up upstream server...

+
+
Time elapsed: 0s
+
 
+
+
+ + + diff --git a/cmd/wol-proxy/wol-proxy.go b/cmd/wol-proxy/wol-proxy.go index 52e1c26..1443f55 100644 --- a/cmd/wol-proxy/wol-proxy.go +++ b/cmd/wol-proxy/wol-proxy.go @@ -3,6 +3,7 @@ package main import ( "bufio" "context" + _ "embed" "errors" "flag" "fmt" @@ -19,6 +20,9 @@ import ( "time" ) +//go:embed index.html +var loadingPageHTML string + var ( flagMac = flag.String("mac", "", "mac address to send WoL packet to") flagUpstream = flag.String("upstream", "", "upstream proxy address to send requests to") @@ -230,6 +234,15 @@ func (p *proxyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err := sendMagicPacket(*flagMac); err != nil { slog.Warn("failed to send magic WoL packet", "error", err) } + + // For root path requests, return loading page with status polling + if path == "/" { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.WriteHeader(http.StatusOK) + fmt.Fprint(w, loadingPageHTML) + return + } + ticker := time.NewTicker(250 * time.Millisecond) timeout, cancel := context.WithTimeout(context.Background(), time.Duration(*flagTimeout)*time.Second) defer cancel()