Okay! I’ve got it working, and it’s looking beautiful. I referred to this: javascript - Nerlify: lambda response was undefined. check your function code again Response with status 500 in 583 ms - Stack Overflow
Then I tweaked the submission-created.js file as below.
require('dotenv').config()
const fetch = require('node-fetch')
const { BUTTONDOWN_API_KEY } = process.env
exports.handler = async event => {
const payload = JSON.parse(event.body).payload
console.log(`Received a submission: ${payload.email}`)
const response = await fetch(
'https://api.buttondown.email/v1/subscribers',
{
method: 'POST',
headers: {
Authorization: `Token ${BUTTONDOWN_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ email: payload.email }),
}
);
let responseText = await response.text();
console.log('response:', responseText);
return {
statusCode: response.status,
body: responseText,
};
}
Now everything works as expected. The signup form works, it passes the data to Buttondown, Buttondown gives a nice response report in the functions tab, and everything is grand!