Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neekey/a793ced27b31874c0930 to your computer and use it in GitHub Desktop.
Save neekey/a793ced27b31874c0930 to your computer and use it in GitHub Desktop.
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