I m writting Ionic app. I
我使用PouchDB作为本地存储,我想将这些数据复制到远程CouchDB服务器iriscouch.com,但我不能让它工作。当我尝试复制db时,我得到如下错误。如果我在我的笔记本电脑上启动服务器localy它工作(没有凭据 - 管理员方)。
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);
});
选项https://username.iriscouch.com:5984/db/?_nonce=VFSibfdoxcnjKz3V net :: ERR_CONNECTION_CLOSED pouchdb.js:5150
CustomPouchError {message:undefined,status:405,statusText:“Method Not Allowed”,name:“unknown_error”,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
});
答案 0 :(得分:3)
405是CORS错误;这意味着您仍然没有正确设置CORS。你试过这个吗? https://github.com/pouchdb/add-cors-to-couchdb
答案 1 :(得分:1)
我遇到了同样的问题,并且能够通过在 cors 标头配置中添加“ x-csrf-token ”来解决此问题> iriscouch配置部分。
这使我的标题配置:
标题:接受,授权,引用,来源,x-csrf-token,内容类型
我希望这可以帮助其他人。