fix: install scripts and improved asset compression

This commit is contained in:
Gareth George
2023-12-24 08:03:26 +00:00
parent fba6c8da86
commit b8c2e81358
7 changed files with 53 additions and 39 deletions

View File

@@ -80,7 +80,25 @@ func main() {
mux := http.NewServeMux()
if box, err := rice.FindBox("webui/dist"); err == nil {
mux.Handle("/", http.FileServer(box.HTTPBox()))
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, "/") {
r.URL.Path += "index.html"
}
f, err := box.Open(r.URL.Path + ".gz")
if err == nil {
defer f.Close()
w.Header().Set("Content-Encoding", "gzip")
http.ServeContent(w, r, r.URL.Path, box.Time(), f)
return
}
f, err = box.Open(r.URL.Path)
if err == nil {
defer f.Close()
http.ServeContent(w, r, r.URL.Path, box.Time(), f)
return
}
http.Error(w, "Not found", http.StatusNotFound)
}))
} else {
zap.S().Warnf("Error loading static assets, not serving UI: %v", err)
}