Skip to content

Commit 2fae168

Browse files
committed
feat(api): 更新客户端配置中的域名处理逻辑
- 添加TLS检查以确定使用HTTP或HTTPS协议 - 集成X-Forwarded-Proto头信息处理 - 添加系统域设置支持 - 优先使用系统域设置覆盖默认域名 - 修复托管配置URL构建逻辑 close: #89
1 parent 4160f8b commit 2fae168

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

api/clients.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,23 @@ func GetSurge(c *gin.Context) {
583583
c.Writer.WriteString(DecodeClash)
584584
return
585585
}
586+
var domain string
587+
if c.Request.TLS != nil {
588+
domain = "https://" + host
589+
} else {
590+
domain = "http://" + host
591+
}
592+
proto := c.Request.Header.Get("X-Forwarded-Proto")
593+
if proto != "" {
594+
domain = proto + "://" + host
595+
}
596+
597+
systemDomain, _ := models.GetSetting("system_domain")
598+
if systemDomain != "" {
599+
domain = systemDomain
600+
}
586601
// 否则就插入头部更新信息
587-
interval := fmt.Sprintf("#!MANAGED-CONFIG %s interval=86400 strict=false", host+url)
602+
interval := fmt.Sprintf("#!MANAGED-CONFIG %s interval=86400 strict=false", domain+url)
588603
// 执行脚本
589604
for _, script := range sub.ScriptsWithSort {
590605
res, err := utils.RunScript(script.Content, DecodeClash, "surge")

0 commit comments

Comments
 (0)