remove web dependencies

This commit is contained in:
2026-02-06 16:13:54 +11:00
parent 730811b76e
commit c68c063ff1
11 changed files with 265 additions and 42 deletions

View File

@@ -47,6 +47,7 @@ func runWebServer(ctx context.Context, d *db.DB, site providers.Site, model, add
}
mux := http.NewServeMux()
staticFiles := http.FileServer(http.FS(sub))
mux.HandleFunc("/api/dashboard", ws.handleDashboard)
mux.HandleFunc("/api/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
@@ -58,7 +59,8 @@ func runWebServer(ctx context.Context, d *db.DB, site providers.Site, model, add
mux.HandleFunc("/chart/", func(w http.ResponseWriter, r *http.Request) {
serveIndex(w, sub)
})
mux.Handle("/", http.FileServer(http.FS(sub)))
mux.Handle("/vendor/", withCacheControl("public, max-age=31536000, immutable", staticFiles))
mux.Handle("/", staticFiles)
srv := &http.Server{
Addr: addr,
@@ -196,3 +198,10 @@ func parseTimeParam(v string) (time.Time, error) {
}
return time.Time{}, errors.New("unsupported time format")
}
func withCacheControl(cacheControl string, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", cacheControl)
next.ServeHTTP(w, r)
})
}