Ive been trying to use an mp3 file from a lyrics API - https://lyrics.ovh in a HTML audio element. But Ive been getting the following cors error (it doesnt happen locally, but when i deploy to gitpages it occurs).
Failed to load resource: net::ERR_CERT_COMMON_NAME_INVALID
This is how Ive been trying to solve it:
I have tried one of the solutions as mentioned here: No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API, to deploy my own proxy to Heroku. It works for one url I need, but for the one containing the mp3 path it doesnt. The response returns status:200, but I get error :unexpected token in JSON.
console error:
GET http://127.0.0.1:5500/[object%20Promise] 404 (Not Found) script.js:89 Uncaught (in promise) SyntaxError: Unexpected token I in JSON at position 0
const cors = https://my-proxy.herokuapp.com
// get Mp3
async function getMP3(url) {
const res = await fetch(`${cors}/${url}`, {
headers: {
"Content-Type": "audio/mpeg",
Accept: "audio/mpeg",
},
});
const data = await res.json(); // this line causes the error
}
// example of url: (proxy url + path to mp3)
https://my-proxy.herokuapp.com/http://cdn-preview-e.deezer.com/stream/c-e6b5f2295c3af5280cc00b3bf842ff57-9.mp3
// audio element
<audio controls>
<source src="${getMP3(url)}" type="audio/mpeg">
</audio>