Skip to content

Instantly share code, notes, and snippets.

@konklone
Created February 21, 2013 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save konklone/5006662 to your computer and use it in GitHub Desktop.
Save konklone/5006662 to your computer and use it in GitHub Desktop.
Using node-http-proxy to proxy normal and WebSockets traffic (for Etherpad) but also having a redirect at the root to direct people to a particular pad.
var http = require('http'),
httpProxy = require('http-proxy');
// Create an instance of node-http-proxy
var proxy = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: 9001
}
});
// Proxy normal HTTP requests
var server = http.createServer(function (req, res) {
// redirect root to specific pad
if (req.url == ('/')) {
res.writeHead(301, {'Location':'http://dc.opendataday.org/p/2013', 'Expires': (new Date).toGMTString()});
res.end();
} else {
proxy.proxyRequest(req, res);
}
});
// Proxy websocket requests too
server.on('upgrade', function(req, socket, head) {
proxy.proxyWebSocketRequest(req, socket, head);
});
server.listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment