HI all,
I have the following netlify function defined:
import fetch from 'node-fetch'
const { MAILERLITE_TOKEN } = process.env
export const handler = async (event, context) => {
const email = JSON.parse(event.body).email
const response = await fetch( 'https://connect.mailerlite.com/api/subscribers', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${MAILERLITE_TOKEN}`,
},
body: JSON.stringify({
email: email,
groups: [
'REDACTED'
]
}),
});
console.log(response)
return new Response(response.status);
};
That is invoked by a form submission on my Hugo site. The strange part of this is that the fetch request returns a 200 and successfully adds a subscriber. The 502 comes in when it returns to the client side. I can’t figure out for the life of me why this is happening. There are no errors or warnings in the function log. I’ve ensured that node-fetch is installed correctly, could it be the way the response is structured? I’ve tried multiple ways but the docs aren’t particularly clear on how to do it.
Thanks in advance.