I am trying to get weather data from dark sky api and I keep getting a cors error. Here is my code:
var url = `https://api.darksky.net/forecast/febb2871126cd24613f32a79c32d4158/${lat},${lon}`;
axios.get(url, config).then(response => {
this.setState({
...
})
}).catch(function (error) {
console.log(error);
});
I get an error "XMLHttpRequest cannot load https://api.darksky.net/forecast/febb2871126cd24613f32a79c32d4158/38.5815719,-121.4943996. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://ebcperez.github.io' is therefore not allowed access."
Looks like the Darksky API server doesn't allow CORS, so you won't be able to make this request from your browser.
A possible solution would be to issue the API request from your application server, and then just display it on the front end.