Skip to content

Instantly share code, notes, and snippets.

@bjfletcher
Last active July 13, 2016 13:57
Show Gist options
  • Save bjfletcher/122b49dbb4d79caf5ad054006aaba198 to your computer and use it in GitHub Desktop.
Save bjfletcher/122b49dbb4d79caf5ad054006aaba198 to your computer and use it in GitHub Desktop.
logging timeouts with Node's http-proxy
var http = require('http');
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({ target: 'http://www.google.co.uk' });
function requestHandler(req, res) {
req.socket.on('timeout', function() {
res.writeHead(502);
res.end("There was an error proxying your request");
});
req.socket.on('error', function() {
res.writeHead(502);
res.end("There was an error proxying your request");
});
proxy.web(req, res, { timeout: 1 }, function (err) {
res.writeHead(502);
res.end("There was an error proxying your request");
});
}
http.createServer(requestHandler).listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment