Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHo3ein <ho3ein.sanaei@gmail.com>2023-05-14 01:21:02 +0300
committerGitHub <noreply@github.com>2023-05-14 01:21:02 +0300
commit7b5dd2d0ee50f315c6ec9a9467851d406558c7b6 (patch)
treeb0b2fd86ea4588eeb84bd65579aa7867e845cbdc
parent62bb42cfabab7e69c758a2e5a2ae0545c6a39710 (diff)
parentb1302c70fbf082e43b50677999325c67bf3709c4 (diff)
Merge pull request #432 from hamid-gh98/main
[HOTFIX] Add basePath to Redirect Middleware
-rw-r--r--web/web.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/web/web.go b/web/web.go
index 849e4beb..1795e1d4 100644
--- a/web/web.go
+++ b/web/web.go
@@ -147,16 +147,17 @@ func (s *Server) getHtmlTemplate(funcMap template.FuncMap) (*template.Template,
return t, nil
}
-func redirectMiddleware() gin.HandlerFunc {
+func redirectMiddleware(basePath string) gin.HandlerFunc {
return func(c *gin.Context) {
// Redirect from old '/xui' path to '/panel'
path := c.Request.URL.Path
redirects := map[string]string{
- "/panel/API": "/panel/api",
- "/xui/API": "/panel/api",
- "/xui": "/panel",
+ "panel/API": "panel/api",
+ "xui/API": "panel/api",
+ "xui": "panel",
}
for from, to := range redirects {
+ from, to = basePath+from, basePath+to
if strings.HasPrefix(path, from) {
newPath := to + path[len(from):]
c.Redirect(http.StatusMovedPermanently, newPath)
@@ -225,7 +226,7 @@ func (s *Server) initRouter() (*gin.Engine, error) {
}
// Apply the redirect middleware (`/xui` to `/panel`)
- engine.Use(redirectMiddleware())
+ engine.Use(redirectMiddleware(basePath))
g := engine.Group(basePath)