【发布时间】:2014-11-10 04:48:34
【问题描述】:
我m writting Ionic app. Im 使用 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);
});
选项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
});
【问题讨论】:
标签: couchdb replication ionic-framework pouchdb