diff --git a/src/webui/server_dev.go b/src/webui/server_dev.go index 93c7f044..1da01b37 100644 --- a/src/webui/server_dev.go +++ b/src/webui/server_dev.go @@ -15,11 +15,20 @@ import ( // setupStaticHandler configures static file serving for development (files from disk) func setupStaticHandler(mux *http.ServeMux, server *WebUIServer) { - // Serve static files from disk for development - with auth + // Serve static files from disk for development staticHandler := http.StripPrefix("/static/", http.FileServer(http.Dir("src/webui/static/"))) - mux.HandleFunc("/static/", server.authMiddleware(func(rw http.ResponseWriter, r *http.Request) { - staticHandler.ServeHTTP(rw, r) - })) + mux.HandleFunc("/static/", func(rw http.ResponseWriter, r *http.Request) { + // Allow access to CSS and JS files without auth (needed for login page) + path := strings.TrimPrefix(r.URL.Path, "/static/") + if strings.HasSuffix(path, ".css") || strings.HasSuffix(path, ".js") { + staticHandler.ServeHTTP(rw, r) + return + } + // For other static files, require auth + server.authMiddleware(func(rw http.ResponseWriter, r *http.Request) { + staticHandler.ServeHTTP(rw, r) + })(rw, r) + }) } // serveFile serves any file from disk or returns 404 if not found diff --git a/src/webui/server_prod.go b/src/webui/server_prod.go index 7a81d246..5558b742 100644 --- a/src/webui/server_prod.go +++ b/src/webui/server_prod.go @@ -25,12 +25,22 @@ func setupStaticHandler(mux *http.ServeMux, server *WebUIServer) { panic("failed to get embedded static files: " + err.Error()) } - // Serve static files from embedded FS - with auth + // Serve static files from embedded FS staticHandler := http.FileServer(http.FS(staticFS)) - mux.HandleFunc("/static/", server.authMiddleware(func(rw http.ResponseWriter, r *http.Request) { - // Strip the /static/ prefix before serving - http.StripPrefix("/static/", staticHandler).ServeHTTP(rw, r) - })) + mux.HandleFunc("/static/", func(rw http.ResponseWriter, r *http.Request) { + // Allow access to CSS and JS files without auth (needed for login page) + path := strings.TrimPrefix(r.URL.Path, "/static/") + if strings.HasSuffix(path, ".css") || strings.HasSuffix(path, ".js") { + // Strip the /static/ prefix before serving + http.StripPrefix("/static/", staticHandler).ServeHTTP(rw, r) + return + } + // For other static files, require auth + server.authMiddleware(func(rw http.ResponseWriter, r *http.Request) { + // Strip the /static/ prefix before serving + http.StripPrefix("/static/", staticHandler).ServeHTTP(rw, r) + })(rw, r) + }) } // serveFile serves any file from embedded files or returns 404 if not found diff --git a/src/webui/static/index.html b/src/webui/static/index.html index f41d9c98..5a8cf906 100644 --- a/src/webui/static/index.html +++ b/src/webui/static/index.html @@ -19,7 +19,10 @@
Network mesh management dashboard