refactor!: move api_url and base_path to config file

This commit is contained in:
Noah Hsu
2022-09-25 17:57:54 +08:00
parent 03dbb3a403
commit 7c32af4649
5 changed files with 52 additions and 23 deletions

View File

@ -10,15 +10,17 @@ import (
)
func GetApiUrl(r *http.Request) string {
api := setting.GetStr(conf.ApiUrl)
protocol := "http"
if r != nil {
api := conf.Conf.SiteURL
if api == "" {
api = setting.GetStr(conf.ApiUrl)
}
if r != nil && api == "" {
protocol := "http"
if r.TLS != nil {
protocol = "https"
}
if api == "" {
api = fmt.Sprintf("%s://%s", protocol, r.Host)
}
api = fmt.Sprintf("%s://%s", protocol, r.Host)
}
strings.TrimSuffix(api, "/")
return api