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: '',
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);
http.createServer(handleReq).listen(PORT, "");
console.log('Server running at' + PORT + '/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment