@@ -58,23 +58,35 @@ func addAdmin(app *gin.Engine, conf *config.Type) {
58
58
// for testing users, proxy admin to target because the build output has not been embed
59
59
dist := getSub (admin , "admin" , "dist" )
60
60
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
+ }
61
66
if err == nil {
62
67
cont , err := ioutil .ReadAll (index )
63
68
logger .FatalIfError (err )
64
69
_ = index .Close ()
65
70
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 )
66
75
renderIndex := func (c * gin.Context ) {
67
76
c .Header ("content-type" , "text/html;charset=utf-8" )
68
77
c .String (200 , sfile )
69
78
}
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
+ })
73
85
logger .Infof ("admin is served from dir 'admin/dist/'" )
74
86
} 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 )
78
90
lang := os .Getenv ("LANG" )
79
91
if strings .HasPrefix (lang , "zh_CN" ) {
80
92
target = "cn-admin.dtm.pub"
@@ -83,7 +95,7 @@ func addAdmin(app *gin.Engine, conf *config.Type) {
83
95
}
84
96
logger .Infof ("admin is proxied to %s" , target )
85
97
}
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 )
87
99
}
88
100
89
101
func proxyAdmin (c * gin.Context ) {
0 commit comments