mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
Add Redirect Middleware for Router
This commit is contained in:
parent
b5ae580d12
commit
c2c61cdd5b
1 changed files with 24 additions and 0 deletions
24
web/web.go
24
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)
|
||||
|
|
Loading…
Reference in a new issue