Skip to content

Instantly share code, notes, and snippets.

@dustin
Created September 9, 2011 18:09
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 dustin/bf62443ce52ae3e8604f to your computer and use it in GitHub Desktop.
Save dustin/bf62443ce52ae3e8604f to your computer and use it in GitHub Desktop.
The couch auth proxy.
var http = require('http');
var url = require('url');
var PORT=8675;
function handleReq(req, res) {
var preq = url.parse(req.url, true);
var myheaders = req.headers;
delete myheaders['host'];
delete myheaders['connection'];
myheaders['Authorization'] = 'Basic Something==';
myheaders['Connection'] = 'close';
var options = {
host: 'single.couchbase.net',
port: 80,
path: req.url,
method: req.method,
headers: myheaders
};
console.log("Fetching", req.url);
var creq = http.request(options, function(cres) {
console.log("Got", cres.statusCode);
res.writeHead(cres.statusCode, cres.headers);
cres.pipe(res);
});
req.pipe(creq);
}
http.createServer(handleReq).listen(PORT, "0.0.0.0");
console.log('Server running at http://0.0.0.0:' + PORT + '/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment