kinduff/dog-api

[Question] How to resolve CORS header 'Access-Control-Allow-Origin' missing in Unity WebGL build

alexandlazaris opened this issue · 5 comments

Hi there, I'm using this api for a Unity3D experiment and am having difficulty with this error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://dog-api.kinduff.com/api/facts. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Screen Shot 2021-12-15 at 9 51 17 pm

Now it's something that occurs only when building a WebGL build in Unity, as if I build a standalone Mac app the error does not occur.

After many tabs and reading through, the consensus seems is for server to hold a response header containing:
Access-Control-Allow-Origin : http://www.my-domain.com. Now this is problematic as I am using the live server you are hosting and not my own.

Is suggestions to resolve this with my current setup?

Hello @alexandlazaris this happens when trying to do a request from the browser instead from a server. I will push a fix to allow CORS for this API.

Excellent @kinduff , thanks for that!

@kinduff Greetings! We're still having the CORS issue. Have you been able to resolve it?

The issue doesn't seem to be fixed yet. Expecting access-control-allow-origin: * in header of api response.

Until I release the new version of the API, I will not provide a fix for this.

Consider using a middleware like CORS Anywhere or any other kind of proxy if you need or want to fetch the information from a browser. The recommended usage is to do it in a server, or even a lambda function.