|
@@ -2123,12 +2123,37 @@ func (s *SubService) BuildURLs(subPath, subJsonPath, subClashPath, subId string)
|
|
|
base := s.settingService.BuildSubURIBase(s.address)
|
|
base := s.settingService.BuildSubURIBase(s.address)
|
|
|
|
|
|
|
|
subURL = s.buildSingleURL(configuredSubURI, base, subPath, subId)
|
|
subURL = s.buildSingleURL(configuredSubURI, base, subPath, subId)
|
|
|
- subJsonURL = s.buildSingleURL(configuredSubJsonURI, base, subJsonPath, subId)
|
|
|
|
|
- subClashURL = s.buildSingleURL(configuredSubClashURI, base, subClashPath, subId)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // When subURI is explicitly configured (reverse-proxy setup), use its
|
|
|
|
|
+ // scheme+host as the base for JSON and Clash URLs so they match the
|
|
|
|
|
+ // reverse-proxy endpoint instead of the raw sub-server port. Fall back
|
|
|
|
|
+ // to the request-derived base if subURI is empty or can't be parsed
|
|
|
|
|
+ // into a scheme+host (e.g. a malformed value with no scheme).
|
|
|
|
|
+ jsonClashBase := base
|
|
|
|
|
+ if configuredSubURI != "" {
|
|
|
|
|
+ if derived := s.extractBaseFromURI(configuredSubURI); derived != "" {
|
|
|
|
|
+ jsonClashBase = derived
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ subJsonURL = s.buildSingleURL(configuredSubJsonURI, jsonClashBase, subJsonPath, subId)
|
|
|
|
|
+ subClashURL = s.buildSingleURL(configuredSubClashURI, jsonClashBase, subClashPath, subId)
|
|
|
|
|
|
|
|
return subURL, subJsonURL, subClashURL
|
|
return subURL, subJsonURL, subClashURL
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// extractBaseFromURI extracts scheme://host from a configured URI.
|
|
|
|
|
+// e.g., "https://example.com/sub-xxx/" → "https://example.com".
|
|
|
|
|
+// Returns "" when the URI is empty or lacks a scheme/host, so callers can
|
|
|
|
|
+// fall back to the request-derived base instead of emitting a broken value.
|
|
|
|
|
+func (s *SubService) extractBaseFromURI(uri string) string {
|
|
|
|
|
+ u, err := url.Parse(uri)
|
|
|
|
|
+ if err != nil || u.Scheme == "" || u.Host == "" {
|
|
|
|
|
+ return ""
|
|
|
|
|
+ }
|
|
|
|
|
+ return fmt.Sprintf("%s://%s", u.Scheme, u.Host)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// buildSingleURL constructs a single URL using configured URI or base components
|
|
// buildSingleURL constructs a single URL using configured URI or base components
|
|
|
func (s *SubService) buildSingleURL(configuredURI, base, basePath, subId string) string {
|
|
func (s *SubService) buildSingleURL(configuredURI, base, basePath, subId string) string {
|
|
|
if configuredURI != "" {
|
|
if configuredURI != "" {
|