I have 2 apps on vercel - one is nextjs, the other is FastAPI in python. The nextjs node api needs to get some data from the FastApi app. I keep getting this content-header mismatch. What am I missing?
cause: RequestContentLengthMismatchError: Request body length does not match content-length header
at AsyncWriter.end (node:internal/deps/undici/undici:8417:19)
at writeIterable (node:internal/deps/undici/undici:8327:16) {
code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
}
My post request in node API:
const body = JSON.stringify({ data: value })
const response = await fetch(`${FAST_API_HOST}/api/data`, {
method: 'POST',
headers: {
'Accept': 'application/json; charset=utf-8',
'Content-Type': 'application/json',
'Content-Length': body.length.toString(),
'Connect': 'keep-alive',
},
body
})
.then(async res => {
if (res.status === 200) return res.json();
else throw new Error(await res.text())
})