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

148
Views
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 answers
Answer question

0

You can just simply use

res.send(proxiedResponse)

about 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!