Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
¿Cómo reenviar una solicitud de nodo usando axios?

En mi servidor express.js estoy haciendo esto para reenviar una solicitud a otro servidor

 async handleRequest(req, res) { const serverUrl = "http://localhost:4000" await req.pipe(request({ url: serverUrl + req.url })).pipe(res); }

Esto está funcionando como se esperaba. Pero he decidido usar axios u got la biblioteca en lugar de la solicitud, ya que la solicitud ya no se mantiene. Pero algo como esto no está funcionando -

 req.pipe(axios({url: serverUrl + req.url})).pipe(res);

estoy recibiendo un error

 (node:88124) UnhandledPromiseRejectionWarning: TypeError: dest.on is not a function at IncomingMessage.Readable.pipe (internal/streams/readable.js:671:8)

¿Cómo puedo arreglar esto? Quiero reenviar la solicitud tal como está sin realizar ningún cambio en el objeto de la solicitud.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debe usar el parámetro responseType con el stream de valor para que axios le brinde la opción de canalizar sus datos de respuesta como un flujo de la siguiente manera:

 axiosResponse.data.pipe(destination); // where destination can be a file or another stream

Además, de hecho, no hay necesidad de await req.pipe porque axios transmitirá la respuesta a su objeto de respuesta expresa (res)

por lo tanto es la respuesta completa:

 const axiosResponse = await axios({ url: serverUrl + req.url, responseType: 'stream' }) axiosResponse.data.pipe(res)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!