From 79eddf7fb2d590fcfbc200a0edafe9887e0bbf94 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Thu, 27 Nov 2025 19:13:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96web=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http/server.go | 12 +++++++-- main.go | 2 +- static/index.html | 14 +++++------ static/js/dashboard.js | 55 ++++++++++++++++++++++++++++++++++++------ 4 files changed, 65 insertions(+), 18 deletions(-) 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 @@
-