Couchdb 使用用户名和密码同步访问
我有一个在虚拟 linux 机器上运行的 couchdb.该数据库已启用并设置了 cors.我添加了一个管理员用户和数据库的密码.我也将 require_valid_user 设置为 true.我正在尝试使用以下代码将网页中的 pouchdb 与在线 couchdb 同步.如果我只是通过地址对于 db(下面的 1),我得到一个对话框,询问用户和密码.同步在此示例中有效.如果我尝试在 URL 中传递用户名和密码(如下面的 2 所示),我会收到同步错误和消息getCheckpoint 被拒绝".任何关于我做错了什么或我应该采取的其他方法的建议将不胜感激.
I have a couchdb running on a virtual linux machine. This db has cors enabled and setup. I have added an admin user and password to the db. I also have require_valid_user set to true. I am trying to sync a pouchdb in a web page with the couchdb online with the code below. If I just pass the address for the db (1 below), I get a dialog box asking for a user and password. The sync works in this example. If I try to pass the user name and password in the URL (as in 2 below), I get a sync error and the message "getCheckpoint rejected with ". Any suggestions on what I am doing wrong or another approach I should taking with this would be greatly appreciated.
谢谢
附:我可以使用用户名和密码浏览到 URL.
P.S. I am able to browse to the URL with the user and password.
var remoteCouch = "http://192.168.1.7:5984/mydb"; //1
//var remoteCouch = "http://userid:password@192.168.1.7:5984/mydb"; //2
sync();
function sync() {
var opts = {live: true};
db.sync(remoteCouch,opts,syncError);
}
推荐答案
我在尝试同步到 cloudant.com 上的 couchDB 时遇到了同样的问题.对我来说,解决方案是在远程服务器的 URL 中使用 https://而不是 http://.URL 的格式应该是:
I had the same problem with the exact same error message trying to sync to a couchDB on cloudant.com. For me, the solution was to use https:// instead of http:// in the URL of the remote server. The format of the URL should be:
https://<api_key>:<key_passwd>@<username>.cloudant.com/<db_name>
因此,尽管我没有本地安装的数据库来测试这一点,但我怀疑您的错误源于当您提供凭据时沙发将请求重定向到安全连接的事实(场景 1).而在场景 2 中不会发生重定向.
So although I do not have a locally installed DB to test this, I suspect your error stems from the fact that couch redirects the request to a secure connection when you provide your credentials (scenario 1). While in scenario 2 no redirect occurs.
相关文章