http-proxy exiting on failure

118 Views Asked by At

I'm using Node.js (and Express, if that matters) to act as a proxy, using http-proxy, like this:

var routingProxy = httpProxy.createServer();

app.use('/api', function (req, res) {
    // ... calculate host and port

  var target = "http://" + host + ":" + port + req.url;
  console.log("proxying starting");
  routingProxy.proxyRequest(req, res, { target: target} );
  console.log('proxy succeeded');
});

Which works fine, when it works. However, if the target server doesn't respond properly, the whole Node instance ends, saying

proxy starting
proxy succeeded

Error: connect ETIMEDOUT
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)

And then the program exits!

The problem is surprisingly obdurate over every change I have thought of.

0

There are 0 best solutions below