Skip to content

Instantly share code, notes, and snippets.

@gonzaloruizdevilla
Created January 18, 2013 08:42
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 gonzaloruizdevilla/4563198 to your computer and use it in GitHub Desktop.
Save gonzaloruizdevilla/4563198 to your computer and use it in GitHub Desktop.
var http = require('http'), httpProxy = require('http-proxy');
/**
* HTTP authentication module.
*/
var auth = require('http-auth');
/**
* Requesting new authentication instance.
*/
var digest = auth({
authRealm : "Private area.",
authList : ['mia:supergirl', 'Carlos:test456', 'Sam:oho']
});
//
// Create a proxy server with custom application logic
//
httpProxy.createServer(function(req, res, proxy) {
digest.apply(req, res, function() {
proxy.proxyRequest(req, res, {
host : 'localhost',
port : 9000
});
});
}).listen(8000);
http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type' : 'text/plain'
});
res.write('request successfully proxied: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment