Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Created March 6, 2011 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominictarr/857228 to your computer and use it in GitHub Desktop.
Save dominictarr/857228 to your computer and use it in GitHub Desktop.
http-proxy does not properly close, and leaves node running.
var http = require('http'),
httpProxy = require('http-proxy'),
request = require('request')
// Create your proxy server
var proxied =
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
})
proxied.listen(9000,c)
function c(){
console.log('created server to proxy')
var proxy =
httpProxy.createServer(9000, 'localhost')
/* //if proxy is a normal server, it will close properly.
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
})*/
proxy.listen(8000,c)
function c(){
console.log('created proxy')
request({uri:'http://localhost:8000'},function (err,res,body){
proxied.close()
proxy.close()//something is left listening and doesn't properly close!
console.log('...node should exit now')
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment