我正在使用PouchDB作为本地存储,我想将这些数据复制到远程CouchDB服务器iriscouch.com,但我无法使其工作。当我尝试复制db时,我得到如下所示的错误。如果我在我的笔记本电脑上本地启动服务器,它可以工作(没有凭据-管理员方)。
var db = new PouchDB('db');
db.replicate.to('https://username:password@username.iriscouch.com:5984/db', {xhrFields:{withCredentials:true}})
//.on('change', function (info) {
// handle change
// console.log("change");
// console.log(info);
.on('uptodate', function (info) {
// handle up-to-date
console.log("uptodate");
console.log(info);
}).on('error', function (err) {
// handle error
console.log("error");
console.log(err);
});OPTIONS https://username.iriscouch.com:5984/db/?_nonce=VFSibfdoxcnjKz3V net::ERR_CONNECTION_CLOSED pouchdb.js:5150
CustomPouchError {消息:未定义,状态: 405,statusText:“不允许使用方法”,名称:"unknown_error",错误: true…} services.js:24
我的CouchDB设置
curl -X PUT $HOST/_config/httpd/enable_cors -d '"true"'
curl -X PUT $HOST/_config/cors/origins -d '"*"'
curl -X PUT $HOST/_config/cors/credentials -d '"true"'
curl -X PUT $HOST/_config/cors/methods -d '"GET, PUT, POST, HEAD, DELETE"'
curl -X PUT $HOST/_config/cors/headers -d '"accept, content-type, origin, referer"'要使其工作,请执行以下操作:
var remoteUrl = 'https://username.iriscouch.com/dbname'
var remote = new PouchDB(remoteUrl, {
Auth: {
username: 'username',
password: 'password'
},
live:true,
withCredentials: true});
发布于 2014-10-21 23:14:15
405是一个CORS错误;这意味着您仍然没有正确设置CORS。你试过这个吗?https://github.com/pouchdb/add-cors-to-couchdb
发布于 2014-11-10 04:48:35
我也遇到了同样的问题,通过将"x-csrf-token“添加到虹膜床配置的cors部分的headers配置中,我能够解决这个问题。
这使得我的头文件配置为:
headers:accept,authorization,referer,origin,x-csrf-token,content-type
我希望这对其他人有帮助。
https://stackoverflow.com/questions/26480212
复制相似问题