diff options
| author | mhsanaei <ho3ein.sanaei@gmail.com> | 2025-09-16 15:38:18 +0300 |
|---|---|---|
| committer | mhsanaei <ho3ein.sanaei@gmail.com> | 2025-09-16 15:38:18 +0300 |
| commit | c4871ef8fe7f57ddb4db94cdea7a85330e749185 (patch) | |
| tree | f2ceb288f432bf7f921b325c9e798ae107cef37d /sub | |
| parent | ecfffa882a159bb2a12954eed0f68eb4ec1a6120 (diff) | |
sub page: improved
Diffstat (limited to 'sub')
| -rw-r--r-- | sub/sub.go | 29 | ||||
| -rw-r--r-- | sub/subService.go | 2 |
2 files changed, 25 insertions, 6 deletions
@@ -11,6 +11,7 @@ import ( "os" "path/filepath" "strconv" + "strings" "x-ui/logger" "x-ui/util/common" @@ -74,11 +75,6 @@ func (s *Server) initRouter() (*gin.Engine, error) { engine.Use(middleware.DomainValidatorMiddleware(subDomain)) } - // Provide base_path in context for templates - engine.Use(func(c *gin.Context) { - c.Set("base_path", "/") - }) - LinksPath, err := s.settingService.GetSubPath() if err != nil { return nil, err @@ -89,6 +85,11 @@ func (s *Server) initRouter() (*gin.Engine, error) { return nil, err } + // Set base_path based on LinksPath for template rendering + engine.Use(func(c *gin.Context) { + c.Set("base_path", LinksPath) + }) + Encrypt, err := s.settingService.GetSubEncrypt() if err != nil { return nil, err @@ -154,11 +155,29 @@ func (s *Server) initRouter() (*gin.Engine, error) { } // Assets: use disk if present, fallback to embedded + // Serve under both root (/assets) and under the subscription path prefix (LinksPath + "assets") + // so reverse proxies with a URI prefix can load assets correctly. + // Determine LinksPath earlier to compute prefixed assets mount. + // Note: LinksPath always starts and ends with "/" (validated in settings). + var linksPathForAssets string + if LinksPath == "/" { + linksPathForAssets = "/assets" + } else { + // ensure single slash join + linksPathForAssets = strings.TrimRight(LinksPath, "/") + "/assets" + } + if _, err := os.Stat("web/assets"); err == nil { engine.StaticFS("/assets", http.FS(os.DirFS("web/assets"))) + if linksPathForAssets != "/assets" { + engine.StaticFS(linksPathForAssets, http.FS(os.DirFS("web/assets"))) + } } else { if subFS, err := fs.Sub(webpkg.EmbeddedAssets(), "assets"); err == nil { engine.StaticFS("/assets", http.FS(subFS)) + if linksPathForAssets != "/assets" { + engine.StaticFS(linksPathForAssets, http.FS(subFS)) + } } else { logger.Error("sub: failed to mount embedded assets:", err) } diff --git a/sub/subService.go b/sub/subService.go index 9f2d93f5..17b05ad0 100644 --- a/sub/subService.go +++ b/sub/subService.go @@ -1109,7 +1109,7 @@ func (s *SubService) BuildPageData(subId string, hostHeader string, traffic xray return PageData{ Host: hostHeader, - BasePath: "/", + BasePath: "/", // kept as "/"; templates now use context base_path injected from router SId: subId, Download: download, Upload: upload, |
