我很难在 PouchDB 和 Sync Gateway 之间设置复制。
我尝试关注 Couchbase 的博客文章,但我也没有成功。
我正在使用angular-pouchdb和ng-pouchdb构建一个 Ionic 应用程序。
到目前为止,这是我想出的:
- 每次我调用
pouchCollection
它时,要么创建一个具有给定名称的新数据库,要么为您提供已创建数据库的引用; - 同步网关负责每个文档的授权。我现在在
GUEST
启用用户的情况下运行它,使用"admin_channels": ["*"]
,所以每个人都应该能够访问所有内容,对吧? CORS
应该启用,因为应用程序和服务器都在同一台机器上运行 (localhost
)- 要以两种方式进行复制,我应该使用
db.sync(URL)
(angular-pouchdb
),其中 URL 类似于http://localhost:4984/prospect/
(并且prospect
可能是数据库名称)
这是我的同步网关config.json
文件:
{
"log": ["CRUD", "REST+", "Access"],
"facebook": {"register": true},
"CORS": {
"Origin": ["http://localhost:8100"],
"LoginOrigin": ["http://localhost:8100"],
"Headers": ["Content-Type"],
"MaxAge": 17280000
},
"databases": {
"prospect": {
"server": "walrus:",
"users": {
"GUEST": {"disabled": false, "admin_channels": ["*"]}
},
"sync":
`
function(doc, oldDoc) {
channel("everything");
}
`
}
}
}
这是我的离子代码:
app.controller('MyCtrl', function($scope, pouchCollection) {
$scope.students = pouchCollection('students');
var URL = 'http://localhost:4984/prospect/';
$scope.students.$db.replicate.sync(URL);
// ...list the array in the view
}
每当我尝试使复制工作时,我在第一次运行时会在控制台中得到以下信息:
GET http://localhost:4984/prospect/_local/jeOaLtKGemQWDpNAPzorJQ%3D%3D?_nonce=1442271117949 404 (Not Found)xhRequest @ pouchdb.js:641625.module.exports @ pouchdb.js:6435ajax @ pouchdb.js:604824.module.exports @ pouchdb.js:6211ajax @ pouchdb.js:989(anonymous function) @ pouchdb.js:994ajaxPromise @ pouchdb.js:993(anonymous function) @ pouchdb.js:1241(anonymous function) @ pouchdb.js:1069979 @ pouchdb.js:10760(anonymous function) @ pouchdb.js:7659(anonymous function) @ pouchdb.js:764679 @ pouchdb.js:1076068.Checkpointer.getCheckpoint @ pouchdb.js:9407(anonymous function) @ pouchdb.js:10076
pouchdb.js:6416 GET http://localhost:4984/prospect/_local/2_QcxPjLD.zmtOXa7VM8Gw%3D%3D?_nonce=1442271117953 404 (Not Found)xhRequest @ pouchdb.js:641625.module.exports @ pouchdb.js:6435ajax @ pouchdb.js:604824.module.exports @ pouchdb.js:6211ajax @ pouchdb.js:989(anonymous function) @ pouchdb.js:994ajaxPromise @ pouchdb.js:993(anonymous function) @ pouchdb.js:1241(anonymous function) @ pouchdb.js:1069979 @ pouchdb.js:10760(anonymous function) @ pouchdb.js:7659(anonymous function) @ pouchdb.js:764679 @ pouchdb.js:10760(anonymous function) @ pouchdb.js:9408
pouchdb.js:6416 GET http://localhost:4984/prospect/_local/jeOaLtKGemQWDpNAPzorJQ%3D%3D?_nonce=1442271118095 404 (Not Found)xhRequest @ pouchdb.js:641625.module.exports @ pouchdb.js:6435ajax @ pouchdb.js:604824.module.exports @ pouchdb.js:6211ajax @ pouchdb.js:989(anonymous function) @ pouchdb.js:994ajaxPromise @ pouchdb.js:993(anonymous function) @ pouchdb.js:1241(anonymous function) @ pouchdb.js:1069979 @ pouchdb.js:10760(anonymous function) @ pouchdb.js:7659(anonymous function) @ pouchdb.js:764679 @ pouchdb.js:10760updateCheckpoint @ pouchdb.js:930368.Checkpointer.updateTarget @ pouchdb.js:936868.Checkpointer.writeCheckpoint @ pouchdb.js:9362finishBatch @ pouchdb.js:9829
(index):28 The above 404 is totally normal. PouchDB is just checking if a remote checkpoint exists.
由于最后一行说这是正常的,我认为一切都很好。
When I run the app in the browser and in the emulator, Sync Gateway says things like:
2015-09-14T19:54:04.913-03:00 HTTP: #001: GET /prospect/?_nonce=1442271244612
2015-09-14T19:54:18.730-03:00 HTTP: #002: GET /prospect/?_nonce=1442271258729
...
2015-09-14T19:56:13.362-03:00 HTTP: #049: GET /prospect/_local/2_QcxPjLD.zmtOXa7VM8Gw==?_nonce=1442271373356
2015-09-14T19:56:13.376-03:00 HTTP: #050: PUT /prospect/_local/2_QcxPjLD.zmtOXa7VM8Gw==
对我来说,看起来一切正常。但我无法让它与 iOS 模拟器或其他浏览器同步。
我错过了什么?