* refactor(auth): replace dashboard sessions with stateless tokens * feat(auth): harden session issuance and distributed enforcement * fix(proxy): preserve trusted proxy compatibility defaults * refactor: address dashboard auth review feedback * refactor: remove classic frontend and flatten web app
35 lines
847 B
Go
35 lines
847 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)
|
|
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, assets)
|
|
} 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))
|
|
})
|
|
}
|
|
}
|