api-docs icon indicating copy to clipboard operation
api-docs copied to clipboard

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

Open ReadyPlayerEmma opened this issue 3 years ago • 6 comments

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

ReadyPlayerEmma avatar Dec 10 '21 07:12 ReadyPlayerEmma

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

JustinGOSSES avatar Dec 21 '21 01:12 JustinGOSSES

Following

katiechurchwell avatar Jan 19 '22 20:01 katiechurchwell

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!

oller avatar Feb 14 '22 22:02 oller

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...

ReadyPlayerEmma avatar Feb 14 '22 22:02 ReadyPlayerEmma

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.

JustinGOSSES avatar Feb 14 '22 23:02 JustinGOSSES

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

kaldaf avatar Nov 26 '22 11:11 kaldaf