alist/server/common/base.go

26 lines
434 B
Go
Raw Normal View History

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