main.go 964 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package router
  2. import (
  3. "embed"
  4. "fmt"
  5. "net/http"
  6. "os"
  7. "strings"
  8. "github.com/QuantumNous/new-api/common"
  9. "github.com/QuantumNous/new-api/middleware"
  10. "github.com/gin-gonic/gin"
  11. )
  12. func SetRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) {
  13. SetApiRouter(router)
  14. SetDashboardRouter(router)
  15. SetRelayRouter(router)
  16. SetVideoRouter(router)
  17. // Gemini File API - completely isolated module
  18. SetGeminiFileRouter(router)
  19. frontendBaseUrl := os.Getenv("FRONTEND_BASE_URL")
  20. if common.IsMasterNode && frontendBaseUrl != "" {
  21. frontendBaseUrl = ""
  22. common.SysLog("FRONTEND_BASE_URL is ignored on master node")
  23. }
  24. if frontendBaseUrl == "" {
  25. SetWebRouter(router, buildFS, indexPage)
  26. } else {
  27. frontendBaseUrl = strings.TrimSuffix(frontendBaseUrl, "/")
  28. router.NoRoute(func(c *gin.Context) {
  29. c.Set(middleware.RouteTagKey, "web")
  30. c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("%s%s", frontendBaseUrl, c.Request.RequestURI))
  31. })
  32. }
  33. }