feat: 增加gzip支持

This commit is contained in:
539943419 committed 2024-08-30 23:48:17 +08:00
1 parent f106d20983
commit 6ea0effa12
3 files changed
+8 -2

No files matched your search

+5 -2
View File
@@ -9,6 +9,7 @@ import (
"os"
"strings"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"miao-directory/api"
@@ -42,9 +43,11 @@ func main() {
c.Redirect(http.StatusMovedPermanently, "/web/")
})
// Serve static files from the embedded filesystem
// Serve static files from the embedded filesystem with gzip compression
staticFS := http.FS(webFS)
router.NoRoute(func(c *gin.Context) {
staticGroup := router.Group("/web")
staticGroup.Use(gzip.Gzip(gzip.DefaultCompression))
staticGroup.GET("/*filepath", func(c *gin.Context) {
http.FileServer(staticFS).ServeHTTP(c.Writer, c.Request)
})