web-router.go 472 B

123456789101112131415161718
  1. package router
  2. import (
  3. "embed"
  4. "github.com/gin-gonic/contrib/static"
  5. "github.com/gin-gonic/gin"
  6. "message-pusher/common"
  7. "message-pusher/middleware"
  8. "net/http"
  9. )
  10. func setWebRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) {
  11. router.Use(middleware.GlobalWebRateLimit())
  12. router.Use(static.Serve("/", common.EmbedFolder(buildFS, "web/build")))
  13. router.NoRoute(func(c *gin.Context) {
  14. c.Data(http.StatusOK, "text/html; charset=utf-8", indexPage)
  15. })
  16. }