Skip to content

Instantly share code, notes, and snippets.

@bjfletcher bjfletcher/index.js
Last active Jul 13, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.