Client → Netlify function (as proxy) → API
The code works, the conctact form emails are sent and 200 response + json success message returned to the netlify function. I can log the response data both as text() and json() in the netlify console, it looks normal there.
But the Netlify function refuses processing the response. Reduced down to this non-working example:
import fetch from 'node-fetch'
const url = 'https://mybackend.com/api/contact/'
const fetchHeaders = {
'Access-Control-Allow-Origin': '*',
'Accept': 'application/json',
'Content-Type': 'application/json',
'Host': 'mybackend.com'
}
exports.handler = async function (event, context) {
const response = await fetch(url, {
method: 'POST',
body: event.body,
headers: fetchHeaders
})
const data = await response.json()
// const data = await response.text()
return {
status: 200,
body: JSON.stringify(data)
// body: data
}
}
In any case the error displayed in the browser network tab is “error decoding lambda response: invalid status code returned from lambda: 0”
I appreciate any help. The information out there on this issue is very limited.