48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
// Package hook
|
|
// @Link https://github.com/bufanyun/hotgo
|
|
// @Copyright Copyright (c) 2023 HotGo CLI
|
|
// @Author Ms <133814250@qq.com>
|
|
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
|
package hook
|
|
|
|
import (
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"hotgo/internal/service"
|
|
"strings"
|
|
)
|
|
|
|
type sHook struct {
|
|
}
|
|
|
|
func init() {
|
|
service.RegisterHook(New())
|
|
}
|
|
|
|
func New() *sHook {
|
|
return &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", "no-cache, must-revalidate")
|
|
r.Response.Header().Set("Pragma", "no-cache")
|
|
r.Response.Header().Set("Expires", "0")
|
|
}
|
|
}
|