export function getOneSite(body){
try {
console.log("getonesite invoked")
console.log(body)
return fetch('http://localhost:3001/oneSite',
{
method: 'POST',
headers: {"Content-Type": "application/json"},
body: JSON.stringify({body}),
})
.then(data => data.json())
} catch (error) {
console.log(error)
}
}
this is the funciton im using to make a post request. the swame kind of request works fine in post man but when i try here it give me
Uncaught (in promise) SyntaxError: Unexpected end of JSON input at services.js:12:1
which points towards the request option object but I cant seem to find what about it is wrong.
here is my api end point
app.post('/oneSite', async (req, res)=> {
console.log(req.body)
const data = await getOnesite(req.body)
res.send(data)
})
and here is the mongoose function behind that
async function getOnesite(body) {
const siteCardData = await siteCardModel.find({_id: body._id}, {_id:0, __v:0}).populate('outages', {'_id':0, '__v':0})
console.log('getonesite invoked')
console.log(body)
console.log(siteCardData[0])
return siteCardData[0]
}