我很难在PouchDB和Sync Gateway之间设置复制。
我试图关注Couchbase的blog post,但我也没有成功。
我正在使用angular-pouchdb和ng-pouchdb构建一个离子应用程序。
这是我到目前为止所得到的:
pouchCollection
时,它都会创建一个具有给定名称的新数据库,或者为您提供已创建数据库的引用; GUEST
用户启用"admin_channels": ["*"]
,所以每个人都应该可以访问所有内容,对吗?CORS
,因为应用和服务器都在同一台计算机上运行(localhost
)db.sync(URL)
(angular-pouchdb
),其中URL类似于http://localhost:4984/prospect/
(并且prospect
可以是数据库名称)< / LI>
醇>
这是我的Sync Gateway 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模拟器或其他浏览器同步。
我错过了什么?
答案 0 :(得分:1)
您的问题..
[2]:* Star频道是每个文档自动添加到该频道的频道。例如,访客用户将被授予*星级频道,在该频道中,您可以获得开放式访问权限,因此任何获得*(星号)的用户都可以看到系统中的所有内容。
[3]:您不需要启用CORS,因为同步网关与您的webapp在同一个域上运行。启用CORS允许Web应用程序访问其他域而不是源域的资源。
LoginOrigin
列表可保护对_session
和_facebook
个终端的访问权限。
[4]:要复制数据,请在app.js
文件中定义用于同步的网址变量,例如:
var SYNC_GATEWAY_URL = 'http://127.0.0.1:4984/prospect/';