ai-gateway/router/web-router.go
2023-04-22 20:39:27 +08:00

23 lines
658 B
Go

package router
import (
"embed"
"gin-template/common"
"gin-template/controller"
"gin-template/middleware"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"net/http"
)
func setWebRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) {
router.Use(middleware.GlobalWebRateLimit())
fileDownloadRoute := router.Group("/")
fileDownloadRoute.GET("/upload/:file", middleware.DownloadRateLimit(), controller.DownloadFile)
router.Use(middleware.Cache())
router.Use(static.Serve("/", common.EmbedFolder(buildFS, "web/build")))
router.NoRoute(func(c *gin.Context) {
c.Data(http.StatusOK, "text/html; charset=utf-8", indexPage)
})
}