nasa / api-docs

api.nasa.gov
http://nasa.github.io/api-docs/
451 stars 109 forks source link

The APOD API no longer appears to provide a CORS-friendly way of loading the image itself #160

Open ReadyPlayerEmma opened 2 years ago

ReadyPlayerEmma commented 2 years ago

Previously, based on older issues, there was a suffix path /direct that could appended to the APOD API which would return the image itself, but with CORS allow-origin headers present. It seems to be the below issue referenced by @amygoodchild in a comment back in January.

I have searched but am unable to find an alternative endpoint in any documentation which provides that ability. Was this feature removed? Could it be enabled again? Or perhaps the APOD webserver where the images are hosted could be updated to add CORS headers when serving image file types from within the paths used for serving APOD images?

Mozilla provides details on the process here: https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image

The original referenced post:

I'm having the same issue. The direct URL is broken and the other one doesn't allow me to use the image url in my code due to a CORS error. Any chance of getting this looked again? Thanks so much!

Originally posted by @amygoodchild in https://github.com/nasa/api-docs/issues/37#issuecomment-759621330

JustinGOSSES commented 2 years ago

You might want to check out the current code for the APOD API here: https://github.com/nasa/apod-api

Also, it might be helpful to know that the APOD API is run entirely separate from the APOD website, so the person who might respond to issues on APOD API has no ability to do any changes on the APOD site or backend.

APOD API is basically a scrapper of APOD

katiechurchwell commented 2 years ago

Following

oller commented 2 years ago

It appears there's been a broader change in CORS headers across multiple NASA APIs. I was using https://ssd-api.jpl.nasa.gov/doc/fireball.html and it now appears to not support CORS requests, and this is an intentional change from NASA. 😞

This was confirmed with an email exchange from someone at NASA when I reported the issue.

If anyone knows of any CORS friendly similar APIs or mirrors, please add them to this thread!

ReadyPlayerEmma commented 2 years ago

It appears there's been a broader change in CORS headers across multiple NASA APIs. I was using https://ssd-api.jpl.nasa.gov/doc/fireball.html and it now appears to not support CORS requests, and this is an intentional change from NASA. 😞

That is unfortunate. It seems rather silly to have a public API but not allow cross-origin requests...

JustinGOSSES commented 2 years ago

Sorry about earlier response. I misunderstood the issue.

I no longer have rights to anything here but just to provide some feedback on this issue.

The problem you're seeing isn't anything to do with api.nasa.gov , it is with apod.nasa.gov. That's the URL you're calling when you have the CORS issue.

API.nasa.gov & APOD.nasa.gov are run by entirely separate groups. Discussing the problem here doesn't get it any views from the folks who run APOD I'm afraid. You might look into the contact details on the APOD page: https://apod.nasa.gov/apod/lib/about_apod.html They may be able to help if they have access to that level of the server, which they may or may not.

As I short term work around, you might look into a CORS proxy as described here: https://stackoverflow.com/questions/43262121/trying-to-use-fetch-and-pass-in-mode-no-cors

Also, in case anyone else stumbles upon this issue, you'll only see this issue for things calling for images via APOD.nasa.gov link and front-end JavaScript. It won't appear if this call to apod.nasa.gov is done via a backend method [curl, python, node.js, etc.]

It should really be fixed on the APOD.nasa.gov side as so many things have been built on those APOD.nasa.gov image URLs, but might flag @MilesCrabbe in case there are less ideal fixes possible on the api.nasa.gov side of things.

kaldaf commented 2 years ago

In my case I couldn't export Canvas because of CORS, I solved it by converting the image to base64 on the server.