mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-29 23:10:35 +00:00
- Introduced RouteTag middleware to set route tags for different API endpoints. - Updated logger to include route tags in log output. - Applied RouteTag middleware across various routers including API, dashboard, relay, video, and web routers for consistent logging.
36 lines
886 B
Go
36 lines
886 B
Go
package router
|
|
|
|
import (
|
|
"embed"
|
|
"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, buildFS embed.FS, indexPage []byte) {
|
|
SetApiRouter(router)
|
|
SetDashboardRouter(router)
|
|
SetRelayRouter(router)
|
|
SetVideoRouter(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.Set(middleware.RouteTagKey, "web")
|
|
c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("%s%s", frontendBaseUrl, c.Request.RequestURI))
|
|
})
|
|
}
|
|
}
|