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 })