Forked from konklone/node-http-proxy-with-redirects.js
Created
July 17, 2013 19:04
-
-
Save ryanhanwu/6023467 to your computer and use it in GitHub Desktop.
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