Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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