23 lines
658 B
Go
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)
|
|
})
|
|
}
|