Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor
Browse files Browse the repository at this point in the history
j2rong4cn committed Jun 15, 2024

Verified

This commit was signed with the committer’s verified signature.
Cruikshanks Alan Cruikshanks
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
@@ -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))
}
@@ -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.