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:
authorHamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com>2023-05-14 00:12:08 +0300
committerHamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com>2023-05-14 00:12:08 +0300
commitc2c61cdd5b9f5b0545253e36d1663f2c19cff16e (patch)
tree3640ecebf2d8285c38c50e2de3b5fe524367f377
parentb5ae580d12b31a8a0db44894aab149870e23ef45 (diff)
Add Redirect Middleware for Router
-rw-r--r--web/web.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/web/web.go b/web/web.go
index 6304d327..849e4beb 100644
--- a/web/web.go
+++ b/web/web.go
@@ -147,6 +147,27 @@ func (s *Server) getHtmlTemplate(funcMap template.FuncMap) (*template.Template,
return t, nil
}
+func redirectMiddleware() 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",
+ }
+ for from, to := range redirects {
+ if strings.HasPrefix(path, from) {
+ newPath := to + path[len(from):]
+ c.Redirect(http.StatusMovedPermanently, newPath)
+ c.Abort()
+ return
+ }
+ }
+ c.Next()
+ }
+}
+
func (s *Server) initRouter() (*gin.Engine, error) {
if config.IsDebug() {
gin.SetMode(gin.DebugMode)
@@ -203,6 +224,9 @@ func (s *Server) initRouter() (*gin.Engine, error) {
engine.StaticFS(basePath+"assets", http.FS(&wrapAssetsFS{FS: assetsFS}))
}
+ // Apply the redirect middleware (`/xui` to `/panel`)
+ engine.Use(redirectMiddleware())
+
g := engine.Group(basePath)
s.index = controller.NewIndexController(g)