diff --git a/http/server.go b/http/server.go index f674a40..2b50314 100644 --- a/http/server.go +++ b/http/server.go @@ -86,8 +86,16 @@ func (s *Server) Start() error { mux.HandleFunc("/ws/stats", s.handleWebSocketStats) } - // 静态文件服务(可后续添加前端界面) - mux.Handle("/", http.FileServer(http.Dir("./static"))) + // 自定义静态文件服务处理器,用于禁用浏览器缓存 + fileServer := http.FileServer(http.Dir("./static")) + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + // 添加Cache-Control头,禁用浏览器缓存 + w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") + w.Header().Set("Pragma", "no-cache") + w.Header().Set("Expires", "Thu, 01 Jan 1970 00:00:00 GMT") + // 使用StripPrefix处理路径 + http.StripPrefix("/", fileServer).ServeHTTP(w, r) + }) s.server = &http.Server{ Addr: fmt.Sprintf("%s:%d", s.config.Host, s.config.Port), diff --git a/main.go b/main.go index c0e86b4..8eb8201 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,7 @@ func createDefaultConfig(configFile string) error { "saveInterval": 300 }, "http": { - "port": 8080, + "port": 8081, "host": "0.0.0.0", "enableAPI": true }, diff --git a/static/index.html b/static/index.html index 3e4d64f..f7c978e 100644 --- a/static/index.html +++ b/static/index.html @@ -240,7 +240,7 @@
-
+
CPU @@ -261,7 +261,7 @@
-