Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Post Purchase Upsell CORS Error when using apps/proxy

Post Purchase Upsell CORS Error when using apps/proxy

rkman
Shopify Partner
1 0 0

I am building Post Purchase Upsell extension using Simplified deployment. Under `ShouldRender` extension point,  I am fetching render data from my app server. The app url differs for each environment and I don't want to hard-code the URL which defeats the purpose of Simplified Deployment. So I am using apps/proxy configuration for making this api call. But the call ends in CORS Error, similar to the issue https://community.shopify.com/c/extensions/cors-issue-with-checkout-ui-extension-fetch-api-app-proxy...

 

I followed the suggestion and made sure that my app has all the necessary "Allow-Origin" headers in the response but the error seems to be coming from App proxy as I don't see any request reaching my server.

 

const fetchCustomerUrl = `https://${inputData.shop.domain}/apps/proxy/token/${inputData.initialPurchase.referenceId}`;
  return fetch(fetchCustomerUrl, {
	credentials: 'include',
	method: 'GET',
	headers: {
		'Content-Type': 'application/json'
	}
  }).then((res) => res.json())

My app server adds the following response header when receiving cross origin requests

 

response.add(new Header(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "POST, GET, OPTIONS, DELETE"))
            .add(new Header(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "Authorization, Content-Type"))
            .add(new Header(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"))
            .add(new Header(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*"))

 

Replies 0 (0)