remove web dependencies
This commit is contained in:
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user