web-router.go 658 B

12345678910111213141516171819202122
  1. package router
  2. import (
  3. "embed"
  4. "gin-template/common"
  5. "gin-template/controller"
  6. "gin-template/middleware"
  7. "github.com/gin-contrib/static"
  8. "github.com/gin-gonic/gin"
  9. "net/http"
  10. )
  11. func setWebRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) {
  12. router.Use(middleware.GlobalWebRateLimit())
  13. fileDownloadRoute := router.Group("/")
  14. fileDownloadRoute.GET("/upload/:file", middleware.DownloadRateLimit(), controller.DownloadFile)
  15. router.Use(middleware.Cache())
  16. router.Use(static.Serve("/", common.EmbedFolder(buildFS, "web/build")))
  17. router.NoRoute(func(c *gin.Context) {
  18. c.Data(http.StatusOK, "text/html; charset=utf-8", indexPage)
  19. })
  20. }