// Package webui embeds the compiled browser application in the Orchestra binary. package webui import ( "embed" "io/fs" "net/http" "path" "strings" ) //go:embed assets/* assets/assets/* var files embed.FS // Handler serves immutable fingerprinted assets and falls back to the SPA for // browser routes. API routes are deliberately not handled here. func Handler() http.Handler { root, _ := fs.Sub(files, "assets") static := http.FileServer(http.FS(root)) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { p := strings.TrimPrefix(path.Clean(r.URL.Path), "/") if p != "" && p != "." { if _, err := fs.Stat(root, p); err == nil { if strings.Contains(p, "/assets/") || strings.HasPrefix(p, "assets/") { w.Header().Set("Cache-Control", "public, max-age=31536000, immutable") } static.ServeHTTP(w, r) return } } w.Header().Set("Cache-Control", "no-cache") b, err := fs.ReadFile(root, "index.html") if err != nil { http.Error(w, "web UI unavailable", http.StatusInternalServerError); return } w.Header().Set("Content-Type", "text/html; charset=utf-8") _, _ = w.Write(b) }) }