alist/server/common/base.go

28 lines
470 B
Go
Raw Normal View History

2022-06-29 08:08:55 +00:00
package common
import (
"fmt"
"net/http"
"strings"
2022-08-03 06:26:59 +00:00
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/setting"
2022-06-29 08:08:55 +00:00
)
2022-08-11 12:32:17 +00:00
func GetApiUrl(r *http.Request) string {
api := conf.Conf.SiteURL
if api == "" {
api = setting.GetStr(conf.ApiUrl)
}
if r != nil && api == "" {
protocol := "http"
2022-08-11 12:32:17 +00:00
if r.TLS != nil {
protocol = "https"
}
api = fmt.Sprintf("%s://%s", protocol, r.Host)
2022-06-30 14:41:55 +00:00
}
2022-08-11 12:32:17 +00:00
strings.TrimSuffix(api, "/")
return api
2022-06-29 08:08:55 +00:00
}