From cb3d03bb3198867713b9834d93b6f90e1346b2d2 Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Mon, 22 Apr 2024 18:36:16 +0800 Subject: [PATCH] Fix: when web file update, dont use cache --- server/middlewares/distCacheControl.go | 14 -------------- server/static/static.go | 14 +++++++++----- 2 files changed, 9 insertions(+), 19 deletions(-) delete mode 100644 server/middlewares/distCacheControl.go diff --git a/server/middlewares/distCacheControl.go b/server/middlewares/distCacheControl.go deleted file mode 100644 index 799cc03..0000000 --- a/server/middlewares/distCacheControl.go +++ /dev/null @@ -1,14 +0,0 @@ -package middlewares - -import "github.com/gin-gonic/gin" - -func NewDistCacheControl(prefix string) gin.HandlerFunc { - return func(ctx *gin.Context) { - if ctx.Request.URL.Path == prefix { - ctx.Header("Cache-Control", "no-cache, max-age=300") - } else { - ctx.Header("Cache-Control", "public, max-age=31536000") - } - ctx.Next() - } -} diff --git a/server/static/static.go b/server/static/static.go index 4854479..f47eb26 100644 --- a/server/static/static.go +++ b/server/static/static.go @@ -8,9 +8,9 @@ import ( "strings" "github.com/gin-gonic/gin" + log "github.com/sirupsen/logrus" "github.com/synctv-org/synctv/cmd/flags" "github.com/synctv-org/synctv/public" - "github.com/synctv-org/synctv/server/middlewares" ) func Init(e *gin.Engine) { @@ -21,9 +21,10 @@ func Init(e *gin.Engine) { web := e.Group("/web") if flags.WebPath == "" { - web.Use(middlewares.NewDistCacheControl("/web/")) - - SiglePageAppFS(web, public.Public, true) + err := SiglePageAppFS(web, public.Public, true) + if err != nil { + log.Fatalf("failed to init fs router: %v", err) + } // err := initFSRouter(web, public.Public.(fs.ReadDirFS), ".") // if err != nil { @@ -37,7 +38,10 @@ func Init(e *gin.Engine) { // } // }) } else { - SiglePageAppFS(web, os.DirFS(flags.WebPath), false) + err := SiglePageAppFS(web, os.DirFS(flags.WebPath), false) + if err != nil { + log.Fatalf("failed to init fs router: %v", err) + } // web.Static("/", flags.WebPath)