#a markdown file
Created
March 4, 2011 07:29
-
-
Save dominictarr/854305 to your computer and use it in GitHub Desktop.
proxy couchdb so that browser side js can query it.
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 connect = require('connect') | |
, httpProxy = require('http-proxy') | |
//when a host:port/couch request comes in, remove /couch from url and proxy to host:5984 | |
function couch (req,res,next){ | |
console.log(req.url) | |
req.url = req.url.replace(/^\/couch/,'') || '/' | |
console.log(req.url) | |
var proxy = new httpProxy.HttpProxy(req, res) | |
proxy.proxyRequest(5984, 'localhost', req, res) | |
} | |
connect.createServer( | |
connect.router(function(app){ | |
app.get('/couch', couch) //catch {couchdb: "welcome",...} | |
, app.get('/couch/*', couch) //catch everything else. limit this to impose security, if you want. also maybe handle POST? | |
}) | |
, connect.logger() | |
, connect.static(__dirname)//serve local .js files | |
).listen(3000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment