Files
new-api/router/main.go

31 lines
752 B
Go
Raw Normal View History

2023-04-22 20:39:27 +08:00
package router
import (
"embed"
"fmt"
2023-04-22 20:39:27 +08:00
"github.com/gin-gonic/gin"
"net/http"
"one-api/common"
"os"
"strings"
2023-04-22 20:39:27 +08:00
)
func SetRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) {
SetApiRouter(router)
SetDashboardRouter(router)
2023-04-23 18:24:11 +08:00
SetRelayRouter(router)
frontendBaseUrl := os.Getenv("FRONTEND_BASE_URL")
if common.IsMasterNode && frontendBaseUrl != "" {
frontendBaseUrl = ""
common.SysLog("FRONTEND_BASE_URL is ignored on master node")
}
if frontendBaseUrl == "" {
SetWebRouter(router, buildFS, indexPage)
} else {
frontendBaseUrl = strings.TrimSuffix(frontendBaseUrl, "/")
router.NoRoute(func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("%s%s", frontendBaseUrl, c.Request.RequestURI))
})
}
2023-04-22 20:39:27 +08:00
}