I'm making the following call to the Dark Sky API:
axios({
url: 'https://api.darksky.net/forecast/[my key]/37.8267,-122.4233',
timeout: 20000,
method: 'get',
responseType: 'json'
})
.then(function(r) {
console.log(r);
})
.catch(function(r){
console.log(r);
});
And I'm getting this error:
XMLHttpRequest cannot load https://api.darksky.net/forecast/[my key]/37.8267,-122.4233. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
I've tried adding a config
as the second parameter to the call, and setting config
to be:
var config = {
headers: {'Access-Control-Allow-Origin': '*'}
};
But, I'm pretty sure that has to be done on the server side? Also tried making the response jsonp
to see if that would fix it, and still nothing. I also tried using simply the fetch()
API, but that didn't work, either.
If it makes any difference, I'm making this call in a React app. How can I just get the JSON and move on with my project?