From addedb1adf9a7ec0ed8c11f0d803429ac38dc48f Mon Sep 17 00:00:00 2001 From: Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> Date: Sun, 14 May 2023 02:31:23 +0430 Subject: [PATCH] HOTFIX redirect middleware to add basePath --- web/web.go | 11 ++++++----- 1 file 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)