I built a proxy server with netlify function.
It worked well at local development environment.
But after deployment, this error occurred.
I’m not sure if the problem is from fetch-blob or netlify function, but I’m asking here because it worked well at local.
It is possible the problem is with the fetch-blob package in a serverless environment.
fetch-blob is a Blob implementation in Node.js, originally from node-fetch.
Try out the alternative package node-fetch to see if it helps resolves the problem.
If the suggestions above does not help, kindly take your time and make sure you go through the API of blob-fetch to make sure you are not missing anything.
Testing locally with netlify dev, I got the data back exactly as expected using the same request on the client side:
let localityQuery = 'Los Angeles';
fetch('/.netlify/functions/get_localities', {
method: 'POST', // Not actually altering anything, but passing a body parameter fails with GET
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: localityQuery
})
})
.then(rawData => rawData.json())
.then(data => {
console.log(data);
})
.catch((error) => console.error(error));
Unfortunately, once I deployed to Netlify, running the same request got me another 502 error, but I thankfully got a more descriptive error by logging the returned data: