Created
February 21, 2013 17:50
-
-
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.
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'); | |
// 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