Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CORS?

I just started getting this error but I'm confused as to how to fix this in my code.

 

["Access to fetch at 'https:\/\/api.darksky.net\/forecast\/myapikey\/lat,long' from origin 'file:\/\/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."]
 
I changed the URL in the above message to hide my apikey... so the url won't work in this example if you try to use it.  Is that "no-cors" mode something I can implement in my companion fetch code?
Best Answer
0 Votes
4 REPLIES 4

I think the CORS setting is set as a header in the server's response, so you need to be able to change the server's behaviour.

 

...That said, I'm probably wrong because I think others are using that API without problems. Maybe there's an account setting somewhere...

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I've got several data feeds coming into my Versa that I've had no problems with over the past months, suddenly in the past day or so I've gotten all off them giving me this CORS error when I look at the app logs.  If that's server side stuff, what has changed in the past couple days to cause my versa to stop being able to read these data streams?

Best Answer
0 Votes

The error message says the origin is "file://".  That's local?  How do I get my companion app to properly fetch then?

Best Answer
0 Votes

After scouring the web, the only solution (really a crappy workaround) I found is to do the following per this web page: 

 

In order to get DarkSky to work with your app, you can use cors-anywhere 271 by putting https://cors-anywhere.herokuapp.com/ in front of your URL:

https://cors-anywhere.herokuapp.com/https://api.darksky.net/forecast/...

 

I followed the above procedure for every one of my web service calls to various sites in my watch face and it works now.  What the heck happened in the past few days that forces me to do this?  Are others facing this same issue?

Best Answer
0 Votes