I’m trying to make an API call to my Express app from a Checkout UI extension using an API proxy, but I’m still encountering a CORS error.
checkout.jsx -
Here are some steps you could try to resolve this issue:
Use the Shopify API Proxy: Shopify provides an API proxy feature that allows you to route requests through the Shopify domain, avoiding CORS issues. Ensure that your app is configured to use the API proxy. You can define the proxy in your app’s configuration and make requests to /apps/<your-app-name> instead of directly to your server.
Set Up CORS in Your Express App: Ensure your Express app is configured to handle CORS properly. Use the cors middleware to allow requests from the Shopify domain. For example:
Ensure Proper Headers: In your fetch request, avoid setting Access-Control-Allow-Origin in the headers. This header is meant to be set by the server, not the client. Remove it from your fetch request.
I tried this, but I’m still getting a CORS error. I also added a console.log to check if my middleware was executing, but it didn’t print anything. This means the request is likely being handled elsewhere before reaching my middleware. Since I’m using the Shopify Express template, it seems that one of the existing middlewares in the template is executing first and preventing mine from running.
And the app is installing correctly, correct? This error is only happening in the context of a checkout extension? Have you reviewed this doc: Configuration
UI extension requests made to the App Proxy of password protected shops is not supported.