diff options
| author | Ho3ein <ho3ein.sanaei@gmail.com> | 2023-05-31 09:17:02 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-31 09:17:02 +0300 |
| commit | 94fad02737d82817ca69f1f05872b49e769a0cb4 (patch) | |
| tree | 55e7ead217c5a3e82791c0edae6ad44de1ba524f /web/web.go | |
| parent | 8442836512d82b705e404bc1749e3000115ba550 (diff) | |
| parent | d694e6eafccad246c63264714897316f671d6428 (diff) | |
Merge pull request #545 from hamid-gh98/main
🔀 New Feature + Fix URLs + Some Improvements 🛠️🌐
Diffstat (limited to 'web/web.go')
| -rw-r--r-- | web/web.go | 34 |
1 files changed, 11 insertions, 23 deletions
@@ -19,6 +19,7 @@ import ( "x-ui/web/controller" "x-ui/web/job" "x-ui/web/locale" + "x-ui/web/middleware" "x-ui/web/network" "x-ui/web/service" @@ -144,28 +145,6 @@ func (s *Server) getHtmlTemplate(funcMap template.FuncMap) (*template.Template, return t, nil } -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", - } - 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) - c.Abort() - return - } - } - c.Next() - } -} - func (s *Server) initRouter() (*gin.Engine, error) { if config.IsDebug() { gin.SetMode(gin.DebugMode) @@ -177,6 +156,15 @@ func (s *Server) initRouter() (*gin.Engine, error) { engine := gin.Default() + webDomain, err := s.settingService.GetWebDomain() + if err != nil { + return nil, err + } + + if webDomain != "" { + engine.Use(middleware.DomainValidatorMiddleware(webDomain)) + } + secret, err := s.settingService.GetSecret() if err != nil { return nil, err @@ -233,7 +221,7 @@ func (s *Server) initRouter() (*gin.Engine, error) { } // Apply the redirect middleware (`/xui` to `/panel`) - engine.Use(redirectMiddleware(basePath)) + engine.Use(middleware.RedirectMiddleware(basePath)) g := engine.Group(basePath) |
