pirateweather icon indicating copy to clipboard operation
pirateweather copied to clipboard

"Cross-Origin Request Blocked" after V2 release

Open aarosmit opened this issue 10 months ago • 5 comments

Describe the issue

Ever since V2 of the API went live, I receive the following error when trying to make an API request:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.pirateweather.net/forecast/key/lat,lon?extend=hourly&units=us. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.

I'm attempting to use Pirate Weather in a Svelte app and this is during testing locally, but my latest build also has the same issue. I'm making the request via Javascript's Fetch API:

let response = await fetch(`https://api.pirateweather.net/forecast/${api_key}/${latitude},${longitude}?extend=hourly&units=us`)

Please let me know if anymore information is needed.

Acknowledgements

  • [X] I have searched this repository and Home Assistant Repository to see if the issue has already been reported.
  • [X] I have read through the API documentation before opening this issue.
  • [X] I have written an informative title.

aarosmit avatar May 03 '24 18:05 aarosmit

Interesting use case, I haven't looked at CORS stuff before, but I can imagine why it would be useful!

I'm not entirely sure on the setup, but I think I've enabled it on the dev.pirateweather.net endpoint. Would it be possible for you to try a request to this endpoint, and if it works, I'll enable it on production?

alexander0042 avatar May 06 '24 17:05 alexander0042

Hi @alexander0042, I just gave the dev endpoint a try, it works like a charm, no CORS issues there.

josezulu avatar May 06 '24 20:05 josezulu

Great! I'll add it to the production endpoint today

alexander0042 avatar May 07 '24 13:05 alexander0042

Thank you @alexander0042!

josezulu avatar May 07 '24 17:05 josezulu

I can confirm it is working in my app now as well. Thank you!

aarosmit avatar May 07 '24 19:05 aarosmit