Created
November 6, 2012 19:37
-
-
Save oeeckhoutte/4026965 to your computer and use it in GitHub Desktop.
[Node] Simple reverse 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 util = require('util'); //Used to debug - inspect cmd | |
d = function (debugString) { | |
console.log(util.inspect(debugString, true, 6, true)); | |
}; | |
t = function (traceString) { | |
console.log('---> ' + traceString); | |
}; | |
var http = require('http'); | |
var httpProxy = require('http-proxy'); | |
var myDevMachineIP = "10.171.182.187"; //local IP | |
var myDevMachinePort = "3000"; | |
/****************** Using HTTP Only ******************************/ | |
// var proxy = new httpProxy.RoutingProxy(); | |
// var server = http.createServer(function (req, res) { | |
// // | |
// // Put your custom server logic here, then proxy | |
// // | |
// proxy.proxyRequest(req, res, { | |
// host: myDevMachineIP, | |
// port: myDevMachinePort | |
// }); | |
// }).listen(3000); | |
/**************************************************************/ | |
/********************** Websocket support *************************/ | |
// | |
// Create a new instance of HttProxy to use in your server | |
// | |
var proxy = new httpProxy.HttpProxy({ | |
target: { | |
host: myDevMachineIP, | |
port: myDevMachinePort | |
} | |
}); | |
// | |
// Create a regular http server and proxy its handler | |
// | |
var server = http.createServer(function (req, res) { | |
proxy.proxyRequest(req, res); | |
}); | |
server.on('upgrade', function(req, socket, head) { | |
// | |
// Proxy websocket requests too | |
// | |
proxy.proxyWebSocketRequest(req, socket, head); | |
}); | |
server.listen(3000); | |
/***************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment