From dcee28d00f5b7b44ffd427622c0f1aab15dbc744 Mon Sep 17 00:00:00 2001 From: chris bell Date: Thu, 11 Jun 2026 21:45:26 -0500 Subject: [PATCH] added change to allow embedding the web portal --- daemon.go | 16 ++++++++++++++++ web/dist/index.html | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 web/dist/index.html diff --git a/daemon.go b/daemon.go index a023dbc..2180918 100644 --- a/daemon.go +++ b/daemon.go @@ -1,20 +1,26 @@ package main import ( + "embed" "encoding/json" "fmt" "io" + "io/fs" "net/http" "os" "os/signal" "path/filepath" "slices" "strconv" + "strings" "sync" "syscall" "time" ) +//go:embed web/dist +var webFS embed.FS + type CommandPayload struct { Command string `json:"command"` } @@ -52,6 +58,12 @@ func StartDaemon(cfg *AppConfig, configPath string) error { mux.HandleFunc("/instances/getConfig", ds.handleGetConfig) mux.HandleFunc("/instances/setConfig", ds.handleSetConfig) + webContent, err := fs.Sub(webFS, "web/dist") + if err != nil { + return fmt.Errorf("failed to load embedded web assets: %w", err) + } + mux.Handle("/", http.FileServer(http.FS(webContent))) + corsWrappedHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS") @@ -63,6 +75,10 @@ func StartDaemon(cfg *AppConfig, configPath string) error { } authCheck := func() bool { + if !strings.HasPrefix(r.URL.Path, "/instances/") { + return true + } + ds.RLock() defer ds.RUnlock() if ds.cfg.Daemon.AuthToken != "" { diff --git a/web/dist/index.html b/web/dist/index.html new file mode 100644 index 0000000..e878447 --- /dev/null +++ b/web/dist/index.html @@ -0,0 +1,2 @@ + +Web UI not embedded in this build. \ No newline at end of file