feat: render local artist images for getArtistInfo2

This commit is contained in:
Zach Myers
2021-12-20 15:46:21 -05:00
committed by sentriz
parent 27ac8e1d25
commit cb6b33a9fb
5 changed files with 83 additions and 38 deletions

View File

@@ -55,6 +55,21 @@ func (c *Controller) Path(rel string) string {
return path.Join(c.ProxyPrefix, rel)
}
func (c *Controller) BaseURL(r *http.Request) string {
scheme := firstExisting(
"http", // fallback
r.Header.Get("X-Forwarded-Proto"),
r.Header.Get("X-Forwarded-Scheme"),
r.URL.Scheme,
)
host := firstExisting(
"localhost:4747", // fallback
r.Header.Get("X-Forwarded-Host"),
r.Host,
)
return fmt.Sprintf("%s://%s", scheme, host)
}
func (c *Controller) WithLogging(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// this is (should be) the first middleware. pass right though it
@@ -87,3 +102,12 @@ func (c *Controller) WithCORS(next http.Handler) http.Handler {
next.ServeHTTP(w, r)
})
}
func firstExisting(or string, strings ...string) string {
for _, s := range strings {
if s != "" {
return s
}
}
return or
}