-
-
Save janl/764daff3643dc553bda9 to your computer and use it in GitHub Desktop.
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
exports.proxy = function (config) { | |
var http = require('http'); | |
return function(url, req, res) { | |
req.host = config.couch.host; | |
req.port = config.couch.port; | |
req.path = url; | |
console.log('proxy %s http://%s:%s%s', req.method, req.host, req.port, req.path); | |
http.globalAgent.maxSockets = 500; | |
var proxy_request = http.request(req, function(res2) { | |
res2.on('data', function(chunk) { | |
res.write(chunk); | |
}); | |
res2.on('end', function() { | |
res.end(); | |
}); | |
}); | |
proxy_request.on('error', function(err) { | |
console.log('problem with proxy: ' + err.message); | |
}); | |
req.on('data', function(req_data) { | |
proxy_request.write(req_data); | |
}); | |
req.on('end', function() { | |
proxy_request.end(); | |
}); | |
req.on('error', function(err) { | |
console.log('problem with request: ' + err.message); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment