mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-21 22:30:46 +08:00
feat(platform): support custom admin path prefix (#25)
This commit is contained in:
+14
-13
@@ -16,17 +16,18 @@ type noticeConfig struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Version float64
|
||||
Addr string
|
||||
Token string
|
||||
Domain string
|
||||
ExternalIP string `yaml:"external_ip"`
|
||||
Database string
|
||||
LogLevel string `yaml:"log_level"`
|
||||
Notice noticeConfig
|
||||
HTTP rhttp.Config
|
||||
DNS dns.Config
|
||||
MySQL mysql.Config
|
||||
RMI rmi.Config
|
||||
FTP ftp.Config
|
||||
Version float64
|
||||
Addr string
|
||||
Token string
|
||||
Domain string
|
||||
ExternalIP string `yaml:"external_ip"`
|
||||
AdminPathPrefix string `yaml:"admin_path_prefix"`
|
||||
Database string
|
||||
LogLevel string `yaml:"log_level"`
|
||||
Notice noticeConfig
|
||||
HTTP rhttp.Config
|
||||
DNS dns.Config
|
||||
MySQL mysql.Config
|
||||
RMI rmi.Config
|
||||
FTP ftp.Config
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ import (
|
||||
log "unknwon.dev/clog/v2"
|
||||
)
|
||||
|
||||
func auth(c *gin.Context) {
|
||||
func (revsuit *Revsuit) auth(c *gin.Context) {
|
||||
c.SetSameSite(http.SameSiteLaxMode)
|
||||
c.SetCookie("token", c.Request.Header["Token"][0], 0, "/revsuit/api/", "", false, true)
|
||||
c.SetCookie("token", c.Request.Header["Token"][0], 0, revsuit.config.AdminPathPrefix, "", false, true)
|
||||
c.String(200, "pong")
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/li4n0/revsuit/frontend"
|
||||
@@ -28,7 +29,7 @@ func (revsuit *Revsuit) registerRouter() {
|
||||
|
||||
func (revsuit *Revsuit) registerPlatformRouter() {
|
||||
// /api need Authorization
|
||||
api := revsuit.http.Router.Group("/revsuit/api")
|
||||
api := revsuit.http.Router.Group(revsuit.config.AdminPathPrefix + "/api")
|
||||
api.Use(func(c *gin.Context) {
|
||||
cookieToken, err := c.Request.Cookie("token")
|
||||
if !(c.Request.Header.Get("Token") == revsuit.http.Token || err == nil && cookieToken.Value == revsuit.http.Token) {
|
||||
@@ -39,7 +40,7 @@ func (revsuit *Revsuit) registerPlatformRouter() {
|
||||
revsuit.http.ApiGroup = api
|
||||
|
||||
//platform routers
|
||||
api.GET("/auth", auth)
|
||||
api.GET("/auth", revsuit.auth)
|
||||
api.GET("/events", revsuit.events)
|
||||
api.GET("/ping", ping)
|
||||
api.GET("/version", version)
|
||||
@@ -53,7 +54,7 @@ func (revsuit *Revsuit) registerHttpRouter() {
|
||||
if err != nil {
|
||||
log.Fatal("Failed to sub path `dist`: %v", err)
|
||||
}
|
||||
revsuit.http.Router.StaticFS("/revsuit/admin", http.FS(fe))
|
||||
revsuit.http.Router.StaticFS(path.Clean(revsuit.config.AdminPathPrefix+"/admin"), http.FS(fe))
|
||||
|
||||
// init settings router group
|
||||
settingsGroup := revsuit.http.ApiGroup.Group("setting")
|
||||
|
||||
@@ -153,6 +153,7 @@ func (revsuit *Revsuit) getPlatformConfig(c *gin.Context) {
|
||||
res["Addr"] = revsuit.config.Addr
|
||||
res["Token"] = revsuit.config.Token
|
||||
res["Domain"] = revsuit.config.Domain
|
||||
res["AdminPathPrefix"] = revsuit.config.AdminPathPrefix
|
||||
res["ExternalIP"] = revsuit.config.ExternalIP
|
||||
res["Database"] = revsuit.config.Database
|
||||
res["LogLevel"] = revsuit.config.LogLevel
|
||||
|
||||
Reference in New Issue
Block a user