I have a node js express api and a react js frontend. I send data using Json.stringify() the erorr below is thrown, the app works as expected but anyways I want to clear this out.
The request
const rawResponse = await fetch('http://localhost:8080/data/report/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
desc: description,
data: measurement,
})
})
const response = await rawResponse.json();
console.log(response);
The end point
app.post('/data/report', (req, res) => {
console.log("[POST] /data/report/")
console.log(req.body)
reports.push(...[].concat(req.body))
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Credentials', true);
res.set({
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
});
res.status(201)
res.send()
})
The error
VM1024:1 Uncaught (in promise) SyntaxError: Unexpected end of JSON input
at dispatcher.js:28