设置 PouchDB 以同步 Gateway Walrus 复制
Setting up PouchDB to Sync Gateway Walrus replication
我很难设置 PouchDB 和 Sync Gateway 之间的复制。
我尝试遵循 Couchbase 的 blog post,但我也没有成功。
我正在使用 angular-pouchdb and ng-pouchdb 构建 Ionic 应用程序。
到目前为止,这是我得到的结果:
- 每次我调用
pouchCollection
时,它要么创建一个具有给定名称的新数据库,要么为您提供已创建数据库的引用;
- Sync Gateway 负责每个文档的授权。我 运行 现在启用
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");
}
`
}
}
}
这是我的 Ionic 代码:
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 模拟器或不同的浏览器同步。
我错过了什么?
针对您的问题..
[2]: *星频道是所有文档自动添加到该频道的频道。例如,来宾用户将被授予 * 星号频道,这为您提供了开放式访问权限,因此任何获得 *(星号)的用户都将能够看到系统中的所有内容。
[3]:您无需启用 CORS,因为同步网关 运行 与您的 webapp 在同一域中。启用 CORS 允许 Web 应用程序访问其他域而不是源域上的资源。
LoginOrigin
列表保护对 _session
和 _facebook
端点的访问。
[4]:要复制您的数据,在 app.js
文件中您将定义一个 URL 变量用于同步,例如:
var SYNC_GATEWAY_URL = 'http://127.0.0.1:4984/prospect/';
我很难设置 PouchDB 和 Sync Gateway 之间的复制。
我尝试遵循 Couchbase 的 blog post,但我也没有成功。
我正在使用 angular-pouchdb and ng-pouchdb 构建 Ionic 应用程序。
到目前为止,这是我得到的结果:
- 每次我调用
pouchCollection
时,它要么创建一个具有给定名称的新数据库,要么为您提供已创建数据库的引用; - Sync Gateway 负责每个文档的授权。我 运行 现在启用
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");
}
`
}
}
}
这是我的 Ionic 代码:
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 模拟器或不同的浏览器同步。
我错过了什么?
针对您的问题..
[2]: *星频道是所有文档自动添加到该频道的频道。例如,来宾用户将被授予 * 星号频道,这为您提供了开放式访问权限,因此任何获得 *(星号)的用户都将能够看到系统中的所有内容。
[3]:您无需启用 CORS,因为同步网关 运行 与您的 webapp 在同一域中。启用 CORS 允许 Web 应用程序访问其他域而不是源域上的资源。
LoginOrigin
列表保护对 _session
和 _facebook
端点的访问。
[4]:要复制您的数据,在 app.js
文件中您将定义一个 URL 变量用于同步,例如:
var SYNC_GATEWAY_URL = 'http://127.0.0.1:4984/prospect/';