I'm a bit new to react and I am trying to fetch Crypto data from the Nomics API. I read their documentations and used axios for my GET request like so:
fetchChartData(currency, start) {
const data = {
key: "key",
currency: currency,
start: start
}
return axios({
method: "get",
url: API_URL + '/exchange-rates/history',
headers: {
"Access-Control-Allow-Origin": "*",
crossorigin: true
},
data
})
}
For which I get:
Access to XMLHttpRequest at 'https://api.nomics.com/v1/currencies/ticker' from origin
'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present
on the requested resource.
So I decided to use Moesif Origin and CORS changer
Access to XMLHttpRequest at 'https://api.nomics.com/v1/exchange-rates/history' from origin 'http://localhost:3000'
has been blocked by CORS policy: Response to preflight request doesn't pass access control check:
It does not have HTTP ok status.
I don't know why it is being blocked because it says "localhost requests are always allowed to ease development" in the documentation.
[![Nomics docs on CORS][1]][1]
My other attempts of fixing this are adding stuff to the headers and proxy. My proxy went like this, (never proxy-ed before):
const API_URL = `https://cors-anywhere.herokuapp.com/https://api.nomics.com/v1`
fetchChartData(currency, start) {
const key = "key";
return axios({
method: "get",
url: API_URL +
'/exchange-rates/history?' +
`?key=${key}
¤cy=${currency}
&start=${start}`
})
}
With proxy, however, I just get a 401 (Unauthorized). [1]: https://i.stack.imgur.com/zIT7L.png