【问题标题】:PouchDB to CouchDB replication Ionic appPouchDB 到 CouchDB 复制 Ionic 应用程序
【发布时间】: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


    【解决方案1】:

    405 是一个 CORS 错误;这意味着您仍然没有正确设置 CORS。你试过这个吗? https://github.com/pouchdb/add-cors-to-couchdb

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,我可以通过在 cors 中的 headers 配置中添加“x-csrf-token”来解决它> iriscouch 配置部分。

      这使我的标题配置:

      headers:accept、authorization、referer、origin、x-csrf-token、content-type

      我希望这对其他人有所帮助。

      【讨论】:

      • 这是在哪里?
      猜你喜欢
      • 1970-01-01
      • 2017-12-19
      • 2013-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      相关资源
      最近更新 更多