Skip to content

Commit c74438a

Browse files
committed
conf add AdminBasePath. serve ui
1 parent 6c85a47 commit c74438a

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

admin/src/utils/request.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import axios from 'axios'
22

33
const request = axios.create({
4-
baseURL: window.basePath || '',
54
timeout: 60000
65
})
76

conf.sample.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
### advanced options
6464
# UpdateBranchAsyncGoroutineNum: 1 # num of async goroutine to update branch status
6565
# TimeZoneOffset: '' #default '' using system default. '+8': Asia/Shanghai; '0': GMT
66+
# AdminBasePath: '' #default '' set admin access base path
6667

6768
# ConfigUpdateInterval: 10 # the interval to update configuration in memory such as topics map... (seconds)
6869
# TimeZoneOffset: '' # default '' using system default. '+8': Asia/Shanghai; '0': GMT

dtmsvr/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ type Type struct {
101101
ConfigUpdateInterval int64 `yaml:"ConfigUpdateInterval" default:"3"`
102102
AlertRetryLimit int64 `yaml:"AlertRetryLimit" default:"3"`
103103
AlertWebHook string `yaml:"AlertWebHook"`
104+
AdminBasePath string `yaml:"AdminBasePath"`
104105
}
105106

106107
// Config config

main.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,35 @@ func addAdmin(app *gin.Engine, conf *config.Type) {
5858
// for testing users, proxy admin to target because the build output has not been embed
5959
dist := getSub(admin, "admin", "dist")
6060
index, err := dist.Open("index.html")
61+
62+
var router gin.IRoutes = app
63+
if len(conf.AdminBasePath) > 0 {
64+
router = app.Group(conf.AdminBasePath)
65+
}
6166
if err == nil {
6267
cont, err := ioutil.ReadAll(index)
6368
logger.FatalIfError(err)
6469
_ = index.Close()
6570
sfile := string(cont)
71+
72+
//replace base path
73+
sfile = strings.Replace(sfile, "\"assets/", "\""+conf.AdminBasePath+"/assets/", -1)
74+
sfile = strings.Replace(sfile, "PUBLIC-PATH-VARIABLE", conf.AdminBasePath, -1)
6675
renderIndex := func(c *gin.Context) {
6776
c.Header("content-type", "text/html;charset=utf-8")
6877
c.String(200, sfile)
6978
}
70-
app.StaticFS("/assets", http.FS(getSub(dist, "assets")))
71-
app.GET("/admin/*name", renderIndex)
72-
app.GET("/", renderIndex)
79+
router.StaticFS("/assets", http.FS(getSub(dist, "assets")))
80+
router.GET("/admin/*name", renderIndex)
81+
router.GET("/", renderIndex)
82+
router.GET("/favicon.ico", func(ctx *gin.Context) {
83+
http.StripPrefix(conf.AdminBasePath, http.FileServer(http.FS(dist))).ServeHTTP(ctx.Writer, ctx.Request)
84+
})
7385
logger.Infof("admin is served from dir 'admin/dist/'")
7486
} else {
75-
app.GET("/", proxyAdmin)
76-
app.GET("/assets/*name", proxyAdmin)
77-
app.GET("/admin/*name", proxyAdmin)
87+
router.GET("/", proxyAdmin)
88+
router.GET("/assets/*name", proxyAdmin)
89+
router.GET("/admin/*name", proxyAdmin)
7890
lang := os.Getenv("LANG")
7991
if strings.HasPrefix(lang, "zh_CN") {
8092
target = "cn-admin.dtm.pub"
@@ -83,7 +95,7 @@ func addAdmin(app *gin.Engine, conf *config.Type) {
8395
}
8496
logger.Infof("admin is proxied to %s", target)
8597
}
86-
logger.Infof("admin is running at: http://localhost:%d", conf.HTTPPort)
98+
logger.Infof("admin is running at: http://localhost:%d%s", conf.HTTPPort, conf.AdminBasePath)
8799
}
88100

89101
func proxyAdmin(c *gin.Context) {

0 commit comments

Comments
 (0)