feat(platform): support custom admin path prefix (#25)

This commit is contained in:
Li4n0
2021-05-31 23:03:39 +08:00
committed by GitHub
parent 42d1e35913
commit f7be2bc2e6
31 changed files with 41 additions and 36 deletions
+14 -13
View File
@@ -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
}
+2 -2
View File
@@ -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")
}
+4 -3
View File
@@ -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")
+1
View File
@@ -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