简体   繁体   中英

PouchDB/CouchDB Replication Fails with Method Not Allowed

Trying to get www.server1.com to communicate to a CouchDB installed on www.server2.com using PouchDB. When trying to replicate the data, I get the following error:

error: true
message: "Database encountered an unknown error"
name: "unknown_error"
status: 405
statusText: "Method Not Allowed"

From the server:

$ curl -X GET http://admin:secret@127.0.0.1:5984/_config/cors
{"credentials":"false","origins":"*","methods":"GET,POST,PUT,DELETE,OPTIONS",
"headers":"accept,authorization,content-type,origin,X-Couch-Id,X-Couch-Rev"}

And in the JavaScript:

var localDB, remoteDB, allSynced = null; 

function initializePouch(){
  localDB = new PouchDB('databaseone');
  remoteDB = new PouchDB('http://admin:secret@<remote ip>:5984/databaseone');

  localDB.info().then(function (info) {
    console.log('Get DB info', info);
  });

  retryReplication();
}

function retryReplication() {
  localDB.sync(remoteDB, {live: true}).on('change', function (change) {
    console.log('Replication done.');
  }).on('error', function (err) {
    console.log('error while replicating');
    console.log(err);
    if( !allSynced ) {
      setTimeout(retryReplication, 30000);
    }
  });
}
initializePouch();

Here is the content of the console:

start.html:229 Get DB info Object {doc_count: 0, update_seq: 0, db_name: "database",
auto_compaction: false}

I tried with and without the admin:secret, but failed each time. Apache CouchDB 1.6.1

Any idea?

This is a CORS error. If I had to guess, I'd say you need to set credentials to true on your server. If you're ever unsure, just run the add-cors-to-couchdb script and try after that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM