Created
July 11, 2013 06:09
-
-
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…
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 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\/(.*)/)); |
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
//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(); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?