Skip to content

Instantly share code, notes, and snippets.

@AvianFlu
Created September 20, 2011 22:29
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 AvianFlu/1230624 to your computer and use it in GitHub Desktop.
Save AvianFlu/1230624 to your computer and use it in GitHub Desktop.
Proxying to a couch based on URL
var http = require('http'),
httpProxy = require('http-proxy'),
couch = {
host: 'localhost',
port: 5984
};
var proxy = new httpProxy.HttpProxy({
target: {host: couch.host, port: couch.port}
});
http.createServer(function (req, res) {
if (/couch\/(.*)/.test(req.url)) {
req.url = req.url.replace('couch/', '');
proxy.proxyRequest(req, res);
}
else {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment