Hi, I am trying to use Netlify functions to POST data from one function to another but I am running into problems. The initial function I call is a background function that runs a Google Page speed audit on several pages - I used a background function because this audit can take several minutes to run. Once this data is collected I want to POST it to another Netlify function that writes it into a Supabase DB.
I have created a reduced test case where i am just trying to send some stringified test data from the background function to the second receiver function, but this doesn’t seem to work - I get no response there at all in the logs.
I know the code is working because if i run it locally in Netlify dev mode it works fine and one function POSTS data to the second no problem, it is only when I deploy that it stops working.
Is there some restriction on sending data between Netlify functions? I asked the AI chatbot and it was useless. It gave me some nonsense about forwarding on the cookies from the first request to the second, but I couldn’t even get a list of the cookies from the request context object to do that.
My receiving function is pretty simple:
export default async (req, context) => {
// Check if the request method is POST
if (req.method !== 'POST') {
return new Response('Method Not Allowed', { status: 405 });
}
try {
// Parse the JSON body from the request
const body = await req.json();
// Process the received data
console.log('Received data:', body);
// Send a response
return new Response(JSON.stringify({ message: 'Data received successfully' }), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
} catch (error) {
console.error('Error processing request:', error);
return new Response(JSON.stringify({ error: 'Error processing request' }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
};
Any help would be much appreciated.
Thanks
My site URL is: https://perf-dashboard-functions.netlify.app