Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Created March 4, 2011 07: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 dominictarr/854305 to your computer and use it in GitHub Desktop.
Save dominictarr/854305 to your computer and use it in GitHub Desktop.
proxy couchdb so that browser side js can query it.
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)

#a markdown file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment