From ca00666ff5b0f155681d7196fc24d9a0269e5fe4 Mon Sep 17 00:00:00 2001 From: cdricms <36056008+cdricms@users.noreply.github.com> Date: Tue, 11 Feb 2025 11:30:15 +0100 Subject: [PATCH] Should do the trick --- backend/api/media/media.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/api/media/media.go b/backend/api/media/media.go index 5d8dc1f..55dae1b 100644 --- a/backend/api/media/media.go +++ b/backend/api/media/media.go @@ -5,6 +5,7 @@ import ( "fmt" "math" "net/http" + "os" "strconv" "fr.latosa-escrima/core" @@ -52,10 +53,20 @@ func HandleMedia(w http.ResponseWriter, r *http.Request) { }.Respond(w, http.StatusInternalServerError) return } - baseURL := utils.GetURL(r) + scheme := "http" + if r.TLS != nil { // Check if the request is over HTTPS + scheme = "https" + } + + // Extract the host + host := r.Host + baseURL := fmt.Sprintf("%s://%s", scheme, host) + if os.Getenv("ENVIRONMENT") != "DEV" { + baseURL += "/api" + } media = utils.Map(media, func(m models.Media) models.Media { m.Author = nil - m.URL = fmt.Sprintf("%s%s/file", baseURL, m.ID) + m.URL = fmt.Sprintf("%s/media/%s/file", baseURL, m.ID) return m })