Fetch API CORS problem
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
-
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.
2
Categories
- 592 All Categories
- Getting Started
- 44 Announcements
- 536 Ask a Question
- 13 Going Live & Publishing
- 57 Website Builder
- 1 App Store
- Custom Branding & Client Management
- 3 Team Collaboration
- 9 eCommerce
- 20 Conversations
- 1 Industry News
- 2 Website Design Feedback
- 1 Random
- 4 Idea Board
- Duda Experts
- 3 Events