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
+1 -1
View File
@@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>RevSuit Control Panel</title><link href="css/chunk-016c45cf.css" rel="prefetch"><link href="css/chunk-0cb5e9e6.css" rel="prefetch"><link href="css/chunk-1da7f23b.css" rel="prefetch"><link href="css/chunk-247d6284.css" rel="prefetch"><link href="css/chunk-330a7e95.css" rel="prefetch"><link href="css/chunk-3d13e56e.css" rel="prefetch"><link href="css/chunk-43748c28.css" rel="prefetch"><link href="css/chunk-49fbda44.css" rel="prefetch"><link href="css/chunk-e039e75a.css" rel="prefetch"><link href="css/chunk-fef965c2.css" rel="prefetch"><link href="js/chunk-016c45cf.js" rel="prefetch"><link href="js/chunk-08f9fbe8.js" rel="prefetch"><link href="js/chunk-0cb5e9e6.js" rel="prefetch"><link href="js/chunk-1da7f23b.js" rel="prefetch"><link href="js/chunk-247d6284.js" rel="prefetch"><link href="js/chunk-330a7e95.js" rel="prefetch"><link href="js/chunk-3d13e56e.js" rel="prefetch"><link href="js/chunk-43748c28.js" rel="prefetch"><link href="js/chunk-49fbda44.js" rel="prefetch"><link href="js/chunk-b241c712.js" rel="prefetch"><link href="js/chunk-e039e75a.js" rel="prefetch"><link href="js/chunk-fef965c2.js" rel="prefetch"><link href="css/app.css" rel="preload" as="style"><link href="css/chunk-vendors.css" rel="preload" as="style"><link href="js/app.js" rel="preload" as="script"><link href="js/chunk-vendors.js" rel="preload" as="script"><link href="css/chunk-vendors.css" rel="stylesheet"><link href="css/app.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but revsuit-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.js"></script><script src="js/app.js"></script></body></html>
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>RevSuit Control Panel</title><link href="css/chunk-016c45cf.css" rel="prefetch"><link href="css/chunk-0cb5e9e6.css" rel="prefetch"><link href="css/chunk-193ec343.css" rel="prefetch"><link href="css/chunk-36508a38.css" rel="prefetch"><link href="css/chunk-43748c28.css" rel="prefetch"><link href="css/chunk-46a53d26.css" rel="prefetch"><link href="css/chunk-49fbda44.css" rel="prefetch"><link href="css/chunk-5fb70d83.css" rel="prefetch"><link href="css/chunk-72839f90.css" rel="prefetch"><link href="css/chunk-740736c7.css" rel="prefetch"><link href="js/chunk-016c45cf.js" rel="prefetch"><link href="js/chunk-0cb5e9e6.js" rel="prefetch"><link href="js/chunk-193ec343.js" rel="prefetch"><link href="js/chunk-27186dd0.js" rel="prefetch"><link href="js/chunk-36508a38.js" rel="prefetch"><link href="js/chunk-43748c28.js" rel="prefetch"><link href="js/chunk-46a53d26.js" rel="prefetch"><link href="js/chunk-49fbda44.js" rel="prefetch"><link href="js/chunk-5fb70d83.js" rel="prefetch"><link href="js/chunk-72839f90.js" rel="prefetch"><link href="js/chunk-740736c7.js" rel="prefetch"><link href="js/chunk-b241c712.js" rel="prefetch"><link href="css/app.css" rel="preload" as="style"><link href="css/chunk-vendors.css" rel="preload" as="style"><link href="js/app.js" rel="preload" as="script"><link href="js/chunk-vendors.js" rel="preload" as="script"><link href="css/chunk-vendors.css" rel="stylesheet"><link href="css/app.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but revsuit-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.js"></script><script src="js/app.js"></script></body></html>
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+4 -4
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -2,7 +2,7 @@ import axios from 'axios'
import {store} from "@/main";
const service = axios.create({
baseURL: '/revsuit/api/', // api的base_url
baseURL: location.pathname.slice(0, -'/admin/'.length) + "/api", // api的base_url
timeout: 5000, // request timeout
validateStatus: function (status) {
if (status === 403) {
+2 -1
View File
@@ -17,7 +17,8 @@
<a-select-option value='error'>ERROR</a-select-option>
<a-select-option value='fatal'>FATAL</a-select-option>
</a-select>
<a-input :disabled="key ==='Addr' && parent==='Http'" v-else v-model="form[key]"/>
<a-input :disabled="(key ==='Addr'||key==='AdminPathPrefix') && parent==='Http'" v-else
v-model="form[key]"/>
</a-form-model-item>
</a-col>
</a-row>
+1 -1
View File
@@ -12,7 +12,7 @@ module.exports = {
'/api': {
target: 'http://localhost:10000',
pathRewrite: {
'^/revsuit/api': '/revsuit/api'
'^/api': '/revsuit/api'
}
}
},
+2 -1
View File
@@ -1,8 +1,9 @@
version: 1.1
version: 1.2
addr: :10000
token:
domain:
external_ip: # You need to make sure that your target can access the server through this ip.
admin_path_prefix: "/revsuit"
database: revsuit.db
log_level: info
+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