mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-07 18:18:00 +00:00
41 lines
992 B
Go
41 lines
992 B
Go
package router
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/QuantumNous/new-api/middleware"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func SetRouter(router *gin.Engine, assets WebAssets) {
|
|
SetApiRouter(router)
|
|
SetDashboardRouter(router)
|
|
SetRelayRouter(router)
|
|
SetTaskPluginProtocolRouter(router)
|
|
SetVideoRouter(router)
|
|
SetTaskRouter(router)
|
|
pluginDispatcher := SetPluginRouter(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, assets, pluginDispatcher)
|
|
} else {
|
|
frontendBaseUrl = strings.TrimSuffix(frontendBaseUrl, "/")
|
|
router.NoRoute(
|
|
pluginDispatcher,
|
|
middleware.RouteTag("web"),
|
|
func(c *gin.Context) {
|
|
c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("%s%s", frontendBaseUrl, c.Request.RequestURI))
|
|
},
|
|
)
|
|
}
|
|
}
|