Last active
July 13, 2016 13:57
-
-
Save bjfletcher/122b49dbb4d79caf5ad054006aaba198 to your computer and use it in GitHub Desktop.
logging timeouts with Node's http-proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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