Skip to content

Commit ce4a295

Browse files
committed
fix!: check https with X-Forwarded-Proto
not read old setting `api_url` and `base_path` from this commit
1 parent bc1babb commit ce4a295

3 files changed

Lines changed: 9 additions & 14 deletions

File tree

internal/conf/const.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ const (
1111
const (
1212
// site
1313
VERSION = "version"
14-
ApiUrl = "api_url"
15-
BasePath = "base_path"
1614
SiteTitle = "site_title"
1715
Announcement = "announcement"
1816
AllowIndexed = "allow_indexed"

server/common/base.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@ package common
33
import (
44
"fmt"
55
"net/http"
6+
stdpath "path"
67
"strings"
78

89
"github.com/alist-org/alist/v3/internal/conf"
9-
"github.com/alist-org/alist/v3/internal/setting"
1010
)
1111

1212
func GetApiUrl(r *http.Request) string {
1313
api := conf.Conf.SiteURL
14-
if api == "" {
15-
api = setting.GetStr(conf.ApiUrl)
14+
if strings.HasPrefix(api, "http") {
15+
return api
1616
}
1717
if r != nil && api == "" {
1818
protocol := "http"
19-
if r.TLS != nil {
19+
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
2020
protocol = "https"
2121
}
22-
api = fmt.Sprintf("%s://%s", protocol, r.Host)
23-
22+
host := r.Host
23+
if r.Header.Get("X-Forwarded-Host") != "" {
24+
host = r.Header.Get("X-Forwarded-Host")
25+
}
26+
api = fmt.Sprintf("%s://%s", protocol, stdpath.Join(host, api))
2427
}
2528
strings.TrimSuffix(api, "/")
2629
return api

server/static/config.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strings"
66

77
"github.com/alist-org/alist/v3/internal/conf"
8-
"github.com/alist-org/alist/v3/internal/setting"
98
"github.com/alist-org/alist/v3/pkg/utils"
109
)
1110

@@ -25,11 +24,6 @@ func getSiteConfig() SiteConfig {
2524
BasePath: u.Path,
2625
Cdn: strings.ReplaceAll(strings.TrimSuffix(conf.Conf.Cdn, "/"), "$version", conf.WebVersion),
2726
}
28-
// try to get old config
29-
if siteConfig.ApiURL == "" {
30-
siteConfig.ApiURL = setting.GetStr(conf.ApiUrl)
31-
siteConfig.BasePath = setting.GetStr(conf.BasePath)
32-
}
3327
if siteConfig.BasePath != "" {
3428
siteConfig.BasePath = utils.FixAndCleanPath(siteConfig.BasePath)
3529
}

0 commit comments

Comments
 (0)