fix: no-cache headers to prevent stale JS, correct go2rtc stream.html URL

This commit is contained in:
Claus Lohmar 2026-08-05 14:02:44 +01:00
parent 03448361da
commit 741983ae82

View file

@ -75,12 +75,16 @@ func (s *Server) registerRoutes() {
s.mux.Handle("/", http.FileServer(http.FS(publicFS))) s.mux.Handle("/", http.FileServer(http.FS(publicFS)))
} }
// middleware wraps handlers with CORS and logging. // middleware wraps handlers with CORS, no-cache, and logging.
func (s *Server) middleware(next http.Handler) http.Handler { func (s *Server) middleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type") w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
// Prevent caching of static files during development.
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
if r.Method == "OPTIONS" { if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)