0

I am pretty new to developing and I am working on an app with node and express. I am having an issue where I get a:

"Access to XMLHttpRequest at 'https://api.darksky.net/forecast/[API_KEY]/38.7907,121.2358' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I do actually have the API key in the code within the project and I have been able to just copy/paste directly into Chrome and I get the data returned.

I'm just lost as to why it works from chrome, but not from my project. Isn't chrome also my local machine? I think I may be able to use JSONP but I'm wondering if there is a better approach?

This is a link to the project on github: https://github.com/ryanmdoyle/BrainBreak

Ryan
  • 79
  • 2
  • 10
  • You should read [The FAQ for the API you are trying to use](https://darksky.net/dev/docs/faq#cross-origin)! – Quentin Dec 20 '18 at 16:56
  • "Isn't chrome also my local machine?" — Your copy of Chrome is. Your visitor's copy of Chrome is not. Chrome only knows that it is a browser visiting a website. It does not know who controls that website. – Quentin Dec 20 '18 at 16:57
  • Thanks @Quentin. I had not previously found that answer. (I've been looking at all sorts of things!) – Ryan Dec 20 '18 at 17:25

0 Answers0