alist/server/common/base.go

23 lines
429 B
Go
Raw Normal View History

2022-06-29 08:08:55 +00:00
package common
import (
"fmt"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/setting"
"net/http"
"strings"
)
func GetBaseUrl(r *http.Request) string {
2022-07-02 08:43:07 +00:00
baseUrl := setting.GetByKey(conf.ApiUrl)
2022-06-30 14:41:55 +00:00
protocol := "http"
if r.TLS != nil {
protocol = "https"
}
2022-06-29 08:08:55 +00:00
if baseUrl == "" {
2022-06-30 14:41:55 +00:00
baseUrl = fmt.Sprintf("%s//%s", protocol, r.Host)
2022-06-29 08:08:55 +00:00
}
strings.TrimSuffix(baseUrl, "/")
return baseUrl
}