fix: set admin frontend cache headers

This commit is contained in:
richjohnrambo
2026-08-28 01:42:14 +08:00
parent 296c9a22a8
commit a04abb0cc8
+15 -1
View File
@@ -8,6 +8,7 @@ package hook
import (
"github.com/gogf/gf/v2/net/ghttp"
"hotgo/internal/service"
"strings"
)
type sHook struct {
@@ -22,10 +23,23 @@ func New() *sHook {
}
func (s *sHook) BeforeServe(r *ghttp.Request) {
s.setAdminStaticCacheHeader(r)
}
func (s *sHook) AfterOutput(r *ghttp.Request) {
s.accessLog(r)
s.lastAdminActive(r)
}
func (s *sHook) setAdminStaticCacheHeader(r *ghttp.Request) {
path := r.URL.Path
if path == "/admin" || path == "/admin/" || path == "/admin/index.html" || path == "/admin/app.config.js" {
r.Response.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
r.Response.Header().Set("Pragma", "no-cache")
r.Response.Header().Set("Expires", "0")
return
}
if strings.HasPrefix(path, "/admin/assets/") {
r.Response.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
}
}