Fetch API CORS problem

Tom_Grissom
Tom_Grissom Member Posts: 1

How do we get around a CORS issue when building a custom widget? Is there a duda proxy? I am trying to build a test by using a dog facts api but I am running into a problem with CORS. It says

"Access to fetch at 'https://dog-facts-api.herokuapp.com/api/v1/resources/dogs?number=1' from origin 'https://my.duda.co' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."

However, disabling CORS can cause other issues. What if I run into this problem with other api requests? what is the best way to get around this in the custom widgets?

Answers

  • Elizabeth_Fedak
    Elizabeth_Fedak Member Posts: 98 MVP

    I deploy my code via a GCP cloud function to be able to set the proper headers when there are CORS requirements so it handles preflight requests etc and I just make a call to my custom function with any relevant data.