Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
j2rong4cn committed Jun 15, 2024
1 parent 45fdafd commit e355856
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions server/common/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func GetApiUrl(r *http.Request) string {
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
protocol = "https"
}
host := r.Host
if r.Header.Get("X-Forwarded-Host") != "" {
host = r.Header.Get("X-Forwarded-Host")
host := r.Header.Get("X-Forwarded-Host")
if host == "" {
host = r.Host
}
api = fmt.Sprintf("%s://%s", protocol, stdpath.Join(host, api))
}
Expand All @@ -32,9 +32,8 @@ func GetApiUrl(r *http.Request) string {
}

func GetApiUrlFromContext(ctx context.Context) string {
var r *http.Request
if c, ok := ctx.(*gin.Context); ok {
r = c.Request
return GetApiUrl(c.Request)
}
return GetApiUrl(r)
return GetApiUrl(nil)
}

0 comments on commit e355856

Please sign in to comment.