gpt4 book ai didi

javascript - PouchDB/CouchDB 复制失败,方法不允许

转载 作者:行者123 更新时间:2023-11-28 00:40:30 24 4
gpt4 key购买 nike

尝试使用 PouchDB 让 www.server1.com 与安装在 www.server2.com 上的 CouchDB 进行通信。当尝试复制数据时,我收到以下错误:

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

来自服务器:

$ 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"}

在 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();

以下是控制台的内容:

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

我尝试过使用和不使用 admin:secret,但每次都失败。Apache CouchDB 1.6.1

有什么想法吗?

最佳答案

这是一个 CORS 错误。如果我不得不猜测,我会说您需要在服务器上将 credentials 设置为 true。如果您不确定,只需运行 add-cors-to-couchdb 脚本,然后再尝试。

关于javascript - PouchDB/CouchDB 复制失败,方法不允许,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27993087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com