Create a gist now

Instantly share code, notes, and snippets.

@dustin /authproxy.js Secret
Created Sep 9, 2011

What would you like to do?
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