mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-20 05:52:24 +00:00
HOTFIX redirect middleware to add basePath
This commit is contained in:
parent
9626379731
commit
addedb1adf
1 changed files with 6 additions and 5 deletions
11
web/web.go
11
web/web.go
|
@ -147,16 +147,17 @@ func (s *Server) getHtmlTemplate(funcMap template.FuncMap) (*template.Template,
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func redirectMiddleware() gin.HandlerFunc {
|
func redirectMiddleware(basePath string) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
// Redirect from old '/xui' path to '/panel'
|
// Redirect from old '/xui' path to '/panel'
|
||||||
path := c.Request.URL.Path
|
path := c.Request.URL.Path
|
||||||
redirects := map[string]string{
|
redirects := map[string]string{
|
||||||
"/panel/API": "/panel/api",
|
"panel/API": "panel/api",
|
||||||
"/xui/API": "/panel/api",
|
"xui/API": "panel/api",
|
||||||
"/xui": "/panel",
|
"xui": "panel",
|
||||||
}
|
}
|
||||||
for from, to := range redirects {
|
for from, to := range redirects {
|
||||||
|
from, to = basePath+from, basePath+to
|
||||||
if strings.HasPrefix(path, from) {
|
if strings.HasPrefix(path, from) {
|
||||||
newPath := to + path[len(from):]
|
newPath := to + path[len(from):]
|
||||||
c.Redirect(http.StatusMovedPermanently, newPath)
|
c.Redirect(http.StatusMovedPermanently, newPath)
|
||||||
|
@ -225,7 +226,7 @@ func (s *Server) initRouter() (*gin.Engine, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the redirect middleware (`/xui` to `/panel`)
|
// Apply the redirect middleware (`/xui` to `/panel`)
|
||||||
engine.Use(redirectMiddleware())
|
engine.Use(redirectMiddleware(basePath))
|
||||||
|
|
||||||
g := engine.Group(basePath)
|
g := engine.Group(basePath)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue