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

149
Vistas
Returning a different response object in express.js

I'm trying to port a proxy feature that is used for debugging purposes from a hapi.js server to an express.js server.

The feature uses the https module to retrieve data from a different server and I want to simply forward the response from this retrieval to the original client.

Simplified code:

server.get('/proxy/*', (req, res) => {
  https.request({
    protocol: 'https:',
    hostname: 'example.com',
    path: req.url.replace(/^\/proxy\//, ''),
    headers: Object.assign({}, req.headers)
  }, (proxiedResponse) => {
    // respond with proxiedResponse here somehow
  });
});

In Hapi, I could do this easily with reply(proxiedResponse); (reply is Hapi's counterpart to res) since reply isn't an actual response object but a function that internally creates and dispatches a response.
Since in Express, res is the actual response object I guess I need to replace/mod it somehow.

Is there a way to do this in an easier way than to explicitly copy every relevant piece of data from proxiedResponse into res?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can just simply use

res.send(proxiedResponse)

about 4 years ago · Santiago Trujillo Denunciar
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