Fix: when web file update, dont use cache

pull/134/head v0.5.0
zijiren233 1 year ago
parent 871310e4f1
commit cb3d03bb31

@ -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()
}
}

@ -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)

Loading…
Cancel
Save