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

fetch response empy after deploy

fetch response empy after deploy

rodito
Shopify Partner
5 0 0

Hello, I am working on a site external to Shopify and I have a front in react and a back in node, in my location it works perfectly but in AWS it stays on and brings an empty response, here is the coidog to see if you can help me:

react:

const sendCart = async () => {
const cartItems = filteredProducts.map((producto) => {
const variantId = producto.variants[0].admin_graphql_api_id;
const quantity = quantities[producto.id];
return { variantId, quantity };
});
try {
const response = await fetch("http://15.168.33.75:4000/cart", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
items: cartItems,
}),
});
if (!response.ok) {
throw new Error(`Error en la solicitud: ${response.statusText}`);
}
const data = await response.json();
console.log("data devuelta", data);
const nuevaVentana = window.open();
if (nuevaVentana) {
nuevaVentana.location.href = data.redirectUrl;
}
} catch (error) {
console.error("Error al llamar a la API:", error.message);

}
};
and my back: 

app.post('/cart', async (req, res) => {

const items = req.body.items;


 


 
const shopifyStoreUrl = mystore
const storefrontAccessToken=mytoken

const lineItems = items.map(item => {
return `{ variantId: "${item.variantId}", quantity: ${item.quantity} }`;
});


 
const consulta = `
mutation {
checkoutCreate(input: {
lineItems: [${lineItems.join(',')}]
}) {
checkout {
id
webUrl
}
checkoutUserErrors {
code
field
message
}
}
}
`;

fetch(`https://${shopifyStoreUrl}/api/2021-04/graphql.json`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Storefront-Access-Token': storefrontAccessToken
},
body: JSON.stringify({ query: consulta })
})
.then(response => response.json())
.then(data => {
 
const redirectUrl = data.data.checkoutCreate.checkout.webUrl;
res.json({ redirectUrl: redirectUrl });
})
.catch(error => console.error('Error:', error));

});
 
please any help, thanks
Replies 0 (0)