package web import ( "embed" "io/fs" "net/http" "strings" ) // Static files embedded at build time //go:embed static/* var staticFiles embed.FS // GetWebUIHandler returns HTTP handler for embedded web UI func GetWebUIHandler() http.Handler { // Try to get the static subdirectory staticFS, err := fs.Sub(staticFiles, "static") if err != nil { // Fallback to empty filesystem if no static files return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") w.WriteHeader(200) w.Write([]byte(` BZZZ Setup

BZZZ Setup

Web UI not yet built. Please build the React app first.

Run: cd install/config-ui && npm run build

`)) }) } return http.FileServer(http.FS(staticFS)) } // IsEmbeddedFileAvailable checks if a file exists in the embedded filesystem func IsEmbeddedFileAvailable(path string) bool { path = strings.TrimPrefix(path, "/") if path == "" { path = "index.html" } _, err := staticFiles.ReadFile("static/" + path) return err == nil } // ServeEmbeddedFile serves a file from the embedded filesystem func ServeEmbeddedFile(w http.ResponseWriter, r *http.Request, path string) { path = strings.TrimPrefix(path, "/") if path == "" { path = "index.html" } content, err := staticFiles.ReadFile("static/" + path) if err != nil { http.NotFound(w, r) return } // Set content type based on file extension contentType := "text/html" if strings.HasSuffix(path, ".js") { contentType = "application/javascript" } else if strings.HasSuffix(path, ".css") { contentType = "text/css" } else if strings.HasSuffix(path, ".json") { contentType = "application/json" } w.Header().Set("Content-Type", contentType) w.Write(content) }