ai-gateway/router/web-router.go

23 lines
603 B
Go
Raw Normal View History

2023-04-22 12:39:27 +00:00
package router
import (
"embed"
"github.com/gin-contrib/gzip"
2023-04-22 12:39:27 +00:00
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"net/http"
2023-04-22 13:14:09 +00:00
"one-api/common"
"one-api/middleware"
2023-04-22 12:39:27 +00:00
)
func SetWebRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) {
router.Use(gzip.Gzip(gzip.DefaultCompression))
2023-04-22 12:39:27 +00:00
router.Use(middleware.GlobalWebRateLimit())
router.Use(middleware.Cache())
router.Use(static.Serve("/", common.EmbedFolder(buildFS, "web/build")))
router.NoRoute(func(c *gin.Context) {
2023-05-21 16:44:27 +00:00
c.Header("Cache-Control", "no-cache")
2023-04-22 12:39:27 +00:00
c.Data(http.StatusOK, "text/html; charset=utf-8", indexPage)
})
}