diff --git a/admin/src/utils/request.ts b/admin/src/utils/request.ts index b538e43..1ce371f 100644 --- a/admin/src/utils/request.ts +++ b/admin/src/utils/request.ts @@ -1,7 +1,6 @@ import axios from 'axios' const request = axios.create({ - baseURL: window.basePath || '', timeout: 60000 }) diff --git a/conf.sample.yml b/conf.sample.yml index 5aa71e9..1b59d61 100644 --- a/conf.sample.yml +++ b/conf.sample.yml @@ -63,6 +63,7 @@ ### advanced options # UpdateBranchAsyncGoroutineNum: 1 # num of async goroutine to update branch status # TimeZoneOffset: '' #default '' using system default. '+8': Asia/Shanghai; '0': GMT +# AdminBasePath: '' #default '' set admin access base path # ConfigUpdateInterval: 10 # the interval to update configuration in memory such as topics map... (seconds) # TimeZoneOffset: '' # default '' using system default. '+8': Asia/Shanghai; '0': GMT diff --git a/dtmsvr/config/config.go b/dtmsvr/config/config.go index 65a2a90..2021db4 100644 --- a/dtmsvr/config/config.go +++ b/dtmsvr/config/config.go @@ -101,6 +101,7 @@ type Type struct { ConfigUpdateInterval int64 `yaml:"ConfigUpdateInterval" default:"3"` AlertRetryLimit int64 `yaml:"AlertRetryLimit" default:"3"` AlertWebHook string `yaml:"AlertWebHook"` + AdminBasePath string `yaml:"AdminBasePath"` } // Config config diff --git a/main.go b/main.go index 388fc72..1ade997 100644 --- a/main.go +++ b/main.go @@ -58,23 +58,35 @@ func addAdmin(app *gin.Engine, conf *config.Type) { // for testing users, proxy admin to target because the build output has not been embed dist := getSub(admin, "admin", "dist") index, err := dist.Open("index.html") + + var router gin.IRoutes = app + if len(conf.AdminBasePath) > 0 { + router = app.Group(conf.AdminBasePath) + } if err == nil { cont, err := ioutil.ReadAll(index) logger.FatalIfError(err) _ = index.Close() sfile := string(cont) + + //replace base path + sfile = strings.Replace(sfile, "\"assets/", "\""+conf.AdminBasePath+"/assets/", -1) + sfile = strings.Replace(sfile, "PUBLIC-PATH-VARIABLE", conf.AdminBasePath, -1) renderIndex := func(c *gin.Context) { c.Header("content-type", "text/html;charset=utf-8") c.String(200, sfile) } - app.StaticFS("/assets", http.FS(getSub(dist, "assets"))) - app.GET("/admin/*name", renderIndex) - app.GET("/", renderIndex) + router.StaticFS("/assets", http.FS(getSub(dist, "assets"))) + router.GET("/admin/*name", renderIndex) + router.GET("/", renderIndex) + router.GET("/favicon.ico", func(ctx *gin.Context) { + http.StripPrefix(conf.AdminBasePath, http.FileServer(http.FS(dist))).ServeHTTP(ctx.Writer, ctx.Request) + }) logger.Infof("admin is served from dir 'admin/dist/'") } else { - app.GET("/", proxyAdmin) - app.GET("/assets/*name", proxyAdmin) - app.GET("/admin/*name", proxyAdmin) + router.GET("/", proxyAdmin) + router.GET("/assets/*name", proxyAdmin) + router.GET("/admin/*name", proxyAdmin) lang := os.Getenv("LANG") if strings.HasPrefix(lang, "zh_CN") { target = "cn-admin.dtm.pub" @@ -83,7 +95,7 @@ func addAdmin(app *gin.Engine, conf *config.Type) { } logger.Infof("admin is proxied to %s", target) } - logger.Infof("admin is running at: http://localhost:%d", conf.HTTPPort) + logger.Infof("admin is running at: http://localhost:%d%s", conf.HTTPPort, conf.AdminBasePath) } func proxyAdmin(c *gin.Context) {