Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda