Created
October 8, 2014 21:43
-
-
Save joshperry/b32559be5a2e05d51c53 to your computer and use it in GitHub Desktop.
HTTP client proxy
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'), | |
EventEmitter = require('event').EventEmitter, | |
httpProxy = require('http-proxy'); | |
var proxyAgent = new http.Agent({ maxSockets: 3 }); | |
proxyAgent.createConnection = function(options) { | |
var clientSocket = registry.getSocket(options.servername); | |
if(!clientSocket) { | |
// Set clientSocket to a future Socket here somehow | |
} | |
return clientSocket; | |
} | |
// Create a proxy dispatcher with our custom agent | |
var proxy = httpProxy.createProxyServer({agent: proxyAgent, ws: true}); | |
// Just call `proxy.web()` to proxy a web request to the target passed in the options | |
// also you can use `proxy.ws()` to proxy a websockets request | |
var server = http.createServer(function(req, res) { | |
proxy.web(req, res, { target: 'http://' + req.hostname }); | |
}); | |
console.log("listening on port 5050") | |
server.listen(5050); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment