mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-06-10 00:13:42 +00:00
52c67d6d92
- Add internal/webui/ package with //go:build embedui tag for optional SPA embedding (handler.go serves static files with SPA fallback) - Add internal/version/ shared semver comparison (DRY: extracted from gateway/update_check.go and updater/updater.go) - Enhance UpdateChecker: release notes, ETag caching, filter lite-v* tags - Add web UI build stage to Dockerfile with ENABLE_EMBEDUI build arg - Simplify CI: 7 Docker variants → 4 (base, latest, full, otel) - Add SHA256 checksums job to release workflow - Add Makefile build-full target (embeds web UI in Go binary) - Default make up now embeds web UI (no separate nginx needed) - Add WITH_WEB_NGINX=1 flag for optional nginx reverse proxy - Update README + 30 translated READMEs: make up, port 18790 - Update docker-compose comments and prepare-env.sh - About dialog: show release notes with markdown rendering - Health card: amber badge for available updates BREAKING: Default Docker setup no longer requires selfservice overlay. Web dashboard served at :18790 (same port as API).
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package webui
|
|
|
|
import (
|
|
"io/fs"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// apiPrefixes are URL prefixes reserved for backend APIs.
|
|
// Requests matching these are never served by the SPA handler.
|
|
var apiPrefixes = []string{"/v1/", "/ws", "/health", "/mcp/"}
|
|
|
|
// Handler returns an http.Handler that serves the embedded SPA.
|
|
// Returns nil if no assets are embedded (built without embedui tag).
|
|
func Handler() http.Handler {
|
|
fsys := Assets()
|
|
if fsys == nil {
|
|
return nil
|
|
}
|
|
fileServer := http.FileServer(http.FS(fsys))
|
|
return &spaHandler{fs: fsys, fileServer: fileServer}
|
|
}
|
|
|
|
type spaHandler struct {
|
|
fs fs.FS
|
|
fileServer http.Handler
|
|
}
|
|
|
|
func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
// Never intercept API routes.
|
|
for _, prefix := range apiPrefixes {
|
|
if strings.HasPrefix(r.URL.Path, prefix) {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
}
|
|
|
|
// Try to serve the file directly.
|
|
path := strings.TrimPrefix(r.URL.Path, "/")
|
|
if path == "" {
|
|
path = "index.html"
|
|
}
|
|
|
|
// Check if file exists in the embedded FS.
|
|
if _, err := fs.Stat(h.fs, path); err == nil {
|
|
// Static assets: set long cache for /assets/* (Vite hashed filenames).
|
|
if strings.HasPrefix(r.URL.Path, "/assets/") {
|
|
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
|
|
}
|
|
h.fileServer.ServeHTTP(w, r)
|
|
return
|
|
}
|
|
|
|
// SPA fallback: serve index.html for any unmatched route.
|
|
// This handles client-side routing (React Router).
|
|
r.URL.Path = "/"
|
|
h.fileServer.ServeHTTP(w, r)
|
|
}
|