mirror of
				https://github.com/songquanpeng/one-api.git
				synced 2025-11-04 15:53:42 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			32 lines
		
	
	
		
			803 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			803 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package router
 | 
						|
 | 
						|
import (
 | 
						|
	"embed"
 | 
						|
	"fmt"
 | 
						|
	"github.com/gin-gonic/gin"
 | 
						|
	"github.com/songquanpeng/one-api/common/config"
 | 
						|
	"github.com/songquanpeng/one-api/common/logger"
 | 
						|
	"net/http"
 | 
						|
	"os"
 | 
						|
	"strings"
 | 
						|
)
 | 
						|
 | 
						|
func SetRouter(router *gin.Engine, buildFS embed.FS) {
 | 
						|
	SetApiRouter(router)
 | 
						|
	SetDashboardRouter(router)
 | 
						|
	SetRelayRouter(router)
 | 
						|
	frontendBaseUrl := os.Getenv("FRONTEND_BASE_URL")
 | 
						|
	if config.IsMasterNode && frontendBaseUrl != "" {
 | 
						|
		frontendBaseUrl = ""
 | 
						|
		logger.SysLog("FRONTEND_BASE_URL is ignored on master node")
 | 
						|
	}
 | 
						|
	if frontendBaseUrl == "" {
 | 
						|
		SetWebRouter(router, buildFS)
 | 
						|
	} else {
 | 
						|
		frontendBaseUrl = strings.TrimSuffix(frontendBaseUrl, "/")
 | 
						|
		router.NoRoute(func(c *gin.Context) {
 | 
						|
			c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("%s%s", frontendBaseUrl, c.Request.RequestURI))
 | 
						|
		})
 | 
						|
	}
 | 
						|
}
 |