* 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
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package router
|
|
|
|
import (
|
|
"embed"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/QuantumNous/new-api/controller"
|
|
"github.com/QuantumNous/new-api/middleware"
|
|
"github.com/gin-contrib/gzip"
|
|
"github.com/gin-contrib/static"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// WebAssets holds the embedded dashboard frontend assets.
|
|
type WebAssets struct {
|
|
BuildFS embed.FS
|
|
IndexPage []byte
|
|
}
|
|
|
|
func SetWebRouter(router *gin.Engine, assets WebAssets) {
|
|
frontendFS := common.EmbedFolder(assets.BuildFS, "web/dist")
|
|
|
|
router.Use(gzip.Gzip(gzip.DefaultCompression))
|
|
router.Use(middleware.GlobalWebRateLimit())
|
|
router.Use(middleware.Cache())
|
|
router.Use(static.Serve("/", frontendFS))
|
|
router.NoRoute(func(c *gin.Context) {
|
|
c.Set(middleware.RouteTagKey, "web")
|
|
if strings.HasPrefix(c.Request.RequestURI, "/v1") || strings.HasPrefix(c.Request.RequestURI, "/api") || strings.HasPrefix(c.Request.RequestURI, "/assets") {
|
|
controller.RelayNotFound(c)
|
|
return
|
|
}
|
|
c.Header("Cache-Control", "no-cache")
|
|
c.Data(http.StatusOK, "text/html; charset=utf-8", assets.IndexPage)
|
|
})
|
|
}
|