diff --git a/main.go b/main.go index 1f6ad75..228e00c 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "net/http" "path/filepath" "time" @@ -52,6 +53,14 @@ func main() { router.Use(gin.ErrorLogger()) + router.Use(func(c *gin.Context) { + path := c.Request.URL.Path + if path == "" || path == "/" { + c.Redirect(http.StatusMovedPermanently, "/my-drive") + } + c.Next() + }) + routes.AddRoutes(router) ui.AddRoutes(router) diff --git a/ui/teldrive-ui b/ui/teldrive-ui index f3f2f5b..ab2936c 160000 --- a/ui/teldrive-ui +++ b/ui/teldrive-ui @@ -1 +1 @@ -Subproject commit f3f2f5b371e407c983e756ad8955f0a8b345ca28 +Subproject commit ab2936c3f24945221f6b800c6e0743b7501ac512 diff --git a/ui/ui.go b/ui/ui.go index aeebaf2..472b835 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -5,6 +5,7 @@ import ( "fmt" "io/fs" "net/http" + "path" "strings" "github.com/gin-gonic/contrib/static" @@ -17,6 +18,17 @@ var staticFS embed.FS func AddRoutes(router gin.IRouter) { embeddedBuildFolder := newStaticFileSystem() fallbackFileSystem := newFallbackFileSystem(embeddedBuildFolder) + + router.Use(func(c *gin.Context) { + isStatic, _ := path.Match("/assets/*", c.Request.URL.Path) + isImg, _ := path.Match("/img/*", c.Request.URL.Path) + if isStatic || isImg { + c.Writer.Header().Set("Cache-Control", "public, max-age=31536000, immutable") + } else { + c.Writer.Header().Set("Cache-Control", "public, max-age=0, s-maxage=0, must-revalidate") + } + c.Next() + }) router.Use(static.Serve("/", embeddedBuildFolder)) router.Use(static.Serve("/", fallbackFileSystem)) }