Hello I am using a Checkout UI Extension to verify some information to be displayed via a remote server. I just cannot seem to get a proxy URL to work with a Checkout UI Extension.
I keep getting this error when using my app proxy:
Access to fetch at 'https://mydomain.myshopify.com/apps/check_war/' from origin 'https://extensions.shopifycdn.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
Checkout.jsx
const proxyUrl = storeUrl+'/apps/check_war/';
console.log('Proxy URL:', proxyUrl);
const warrantyResponse = await fetch(proxyUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: cartLine.merchandise.product.id,
}),
});
shopify.app.toml
[app_proxy]
prefix = "apps"
subpath = "check_war"
url = "https://my-remote-server/warranty/dev/send_check.php"
content_type = "application/json"
send_check.php (on remote server)
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS, GET');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
header('Content-Type: application/json');
// Handle preflight OPTIONS request
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
Now this DOES work when I use my full url https://my-remote-server/warranty/dev/send_check.php
but clearly I do not want my reomote server domain to be exposed, especially in checkout..hence the proxy.
Wondering if it is because I have to use a absolute URL instead of a relative like I do in other non-checkout UI apps? When using a relative
URL it doesn’t know.