Created
December 11, 2013 21:19
-
-
Save gevorg/7918633 to your computer and use it in GitHub Desktop.
Not proxy authentication for http-proxy/http-auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
httpProxy = require('http-proxy'); | |
// Authentication module. | |
var auth = require('../lib/http-auth'); | |
var basic = auth.basic({ | |
realm: "Simon Area." | |
}, function (username, password, callback) { // Custom authentication method. | |
callback(username === "Tina" && password === "Bullock"); | |
} | |
); | |
// | |
// Create a new instance of HttProxy to use in your server | |
// | |
var proxy = new httpProxy.RoutingProxy(); | |
// | |
// Create a regular http server and proxy its handler | |
// | |
http.createServer(basic, function (req, res) { | |
// | |
// Put your custom server logic here, then proxy | |
// | |
proxy.proxyRequest(req, res, { | |
host: 'localhost', | |
port: 9000 | |
}); | |
}).listen(8001); | |
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