From 31871147806c2b4a17130f1c9e7de6c2cc7f9cc0 Mon Sep 17 00:00:00 2001
From: Andy Oknen
Date: Wed, 30 Jul 2025 13:21:30 +0000
Subject: [PATCH] Refactor static file serving in WebUI to allow CSS and JS
access without authentication, and implement theme toggle functionality in
login and main pages
---
src/webui/server_dev.go | 17 ++-
src/webui/server_prod.go | 20 ++-
src/webui/static/index.html | 33 ++++-
src/webui/static/lang/en.js | 9 +-
src/webui/static/lang/ru.js | 9 +-
src/webui/static/login.html | 173 +++++++++++++++++------
src/webui/static/style.css | 273 ++++++++++++++++++++++++++----------
7 files changed, 408 insertions(+), 126 deletions(-)
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
+
+