I have this code:
router.get('/findRecord', authCheck, (req, res) => {
let amountOfTokens = req.session.amountOfTokens
request.post({
url: 'https://myurl.com/user_records',
headers: {
"Cookie": req.headers?.cookie,
},
json: {
max_date: new Date().valueOf()
}
}, async function(err, httpResponse, body) {
// console.log(body)
if (err) {
console.log(err)
} else {
if (amountOfTokens == undefined || amountOfTokens == null) {
res.redirect('/dashboard')
}
let numOfRecords = body.length
res.render('dashboard.ejs', {data: req.data, body: body, amountOfTokens: amountOfTokens, numOfRecords: numOfRecords})
}
})
})
what happens is, when I render doing this:
res.render('dashboard.ejs', {data: req.data, body: body, amountOfTokens: amountOfTokens, numOfRecords: numOfRecords})
on the front-end, it somehow returns content-type: json header and json content
and the browser isn't rendering the page, just the shows JSON header and the path to what the page that were supposed to be going to.
and body, which returns all the users records, looks like this:
[
{
id: '912342930198368362323',
user: 'xxx@gmail.com',
name: 'hello world',
date: 1655400772,
input: [ [Object], [Object] ],
record_type: 'type1',
output: 'hey',
tokens: 43
}
]
im not sure why this is happening. could someone share what they think could be the problem?