Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
sending content-type json instead of rendering page

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?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda