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:
authormhsanaei <ho3ein.sanaei@gmail.com>2025-09-16 15:38:18 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2025-09-16 15:38:18 +0300
commitc4871ef8fe7f57ddb4db94cdea7a85330e749185 (patch)
treef2ceb288f432bf7f921b325c9e798ae107cef37d /sub/sub.go
parentecfffa882a159bb2a12954eed0f68eb4ec1a6120 (diff)
sub page: improved
Diffstat (limited to 'sub/sub.go')
-rw-r--r--sub/sub.go29
1 files changed, 24 insertions, 5 deletions
diff --git a/sub/sub.go b/sub/sub.go
index 7931b24d..b7e2603e 100644
--- a/sub/sub.go
+++ b/sub/sub.go
@@ -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)
}