Skip to content

Instantly share code, notes, and snippets.

@janl

janl/proxy.js Secret

Created January 16, 2014 15:49
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 janl/764daff3643dc553bda9 to your computer and use it in GitHub Desktop.
Save janl/764daff3643dc553bda9 to your computer and use it in GitHub Desktop.
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