mongodbnetlify-function

Netlify function returns empty axios response on deploy only


I created a netlify function to query data from an external api via an axios get request. The function runs fine when I try it locally with netlify dev. If I try out the deployed version it only gives me an empty string as response.

I tried already a few solutions but nothing helped, thats my function:

return axios
.get(url)
.then((resp) => {
  return {
    statusCode: 200,
    body: JSON.stringify(resp.data),
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
  };
})
.catch((error) => {
  console.error('error', error);
  return {
    statusCode: 500,
    body: error.toString(),
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
  };
});

Additionally I tried the same function with a mongodb cloud functions and get the same empty response. I always get a 200 response code and there is no error thrown in the function


Solution

  • I fixed it now by using firebase cloud functions. I am not sure why that fixed it, maybe it was because of the location of the server where the functions is beeing executed