Seem like whenever I add headers to the sandbox fetch in checkout ui extension, it causes cors issue. When I remove them it works as expected. May I know why this is happening?
Access to fetch at 'https://mid-complexity-going-heat.trycloudflare.com/api/checkout-offer' from origin 'https://cdn.shopify.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: 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.
Yeah so you need to set the CORS headers in response to the OPTIONS request.
You can read more about CORS and understanding cross origin requests here, its really helpful Cross-Origin Resource Sharing (CORS) - HTTP | MDN
It’ll end up looking something like this, please do not copy and paste this without understanding it as it may cause you problems otherwise
It depends on your setup, if you are automatically responding to CORS requests with the framework. But not allowing credentials then only when you add credentials would it fail etc.
I would look into CORS and how your chosen framework handles it
If you inspect in the browser and watch the network requests (again depending on framework) this might give you some hints at what is going on.
I believe there isn’t any issue with the headers configuration on the server/framework. It seems like option requests via the cloudflare tunnel created by shopify cli for development is not being passed on to the server causing the issue.
I only run into this problem recently developing a POS UI extension app. The same fetch code used to work fine a while back. Did anyone come across a solution?