Skip to content

Instantly share code, notes, and snippets.

@toddbluhm
Created July 11, 2013 06:09
Show Gist options
  • Save toddbluhm/5972922 to your computer and use it in GitHub Desktop.
Save toddbluhm/5972922 to your computer and use it in GitHub Desktop.
This is a modified version of the Cloudant reverse-proxy solution for setting up a CORS Couchdb request. The version uses the nano framework instead of request framework which allows for the use of cookie authentication rather than just hardcoded basic auth. This solution was tested using Pouchdb in the browser, reverse-proxied back through a no…
var forward = require('./middleware/forward.js'); //reverse proxy
var nano = require('connect-nano');
// instantiate `app` et al
//After app.use(express.cookieParser());
app.use(nano('https://username.cloudant.com')),
app.use(forward(/\/db\/(.*)/));
//npm connect-nano must be installed
var nano = require('connect-nano');
module.exports = function (pattern, host) {
return function (req, res, next) {
if(req.url.match(pattern)) {
var db_url = req.url.match(pattern)[1]
, db = db_url.split('/')[0]
, db_path = db_url.replace(db,'').substr(1);
console.log(db_url);
req.pipe(req.nano.request({db:db, path:db_path, method:req.method.toLowerCase()})).pipe(res);
} else {
next();
}
};
};
@Cottin
Copy link

Cottin commented Jan 3, 2014

curl -X GET https://localhost:3000/db/_session

gives me back {"ok":true, "info":{"authentication_db":"_users", ... }


But when doing a post

curl -X POST https://localhost:3000/db/_session --data "user=myuser&password=mypassword"

it's peding for 30 seconds and then returns a curl: (52) Empty reply from server

Any tips about what I'm doing wrong?

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