Netlify deployment preview url of a page impacted by the error (continue through checkout process to payment details): Data Strategy Professionals
Trying to fetch from one Netlify Lambda function to another.
This code works fine in dev but not in the deployment preview. I’m getting a “502 Bad Gateway” error. Can someone help me understand what I’m doing wrong?
In the Netlify function handle-payment-intent.js, I’m calling
async function calculateShippingAndTaxes(intent, address) {
try {
const shippingResponse = await fetch(process.env.URL + "/.netlify/functions/calculate-shipping", {
method: "POST",
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Content-Type",
"Content-Type": "application/json",
},
body: JSON.stringify({
address,
paymentName: intent.description,
}),
});
const shippingData = await shippingResponse.json();
const shippingAmt = shippingData?.shipping_cost?.amount;
const taxResponse = await fetch(process.env.URL + "/.netlify/functions/calculate-taxes", {
method: "POST",
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Content-Type",
"Content-Type": "application/json",
},
body: JSON.stringify({
price: intent.amount,
address,
paymentName: intent.description,
shippingAmt,
taxCode: intent?.metadata?.taxCode, // txcd_99999999 (General - Tangible Goods)
}),
});
I think I don’t understand why process.env.URL
isn’t where the calculate-shipping
and calculate-taxes
live… Thanks in advance!!