0

我很难在 PouchDB 和 Sync Gateway 之间设置复制。

我尝试关注 Couchbase 的博客文章,但我也没有成功。

我正在使用angular-pouchdbng-pouchdb构建一个 Ionic 应用程序。

到目前为止,这是我想出的:

  1. 每次我调用pouchCollection它时,要么创建一个具有给定名称的新数据库,要么为您提供已创建数据库的引用;
  2. 同步网关负责每个文档的授权。我现在在GUEST启用用户的情况下运行它,使用"admin_channels": ["*"],所以每个人都应该能够访问所有内容,对吧?
  3. CORS应该启用,因为应用程序和服务器都在同一台机器上运行 ( localhost)
  4. 要以两种方式进行复制,我应该使用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 模拟器或其他浏览器同步。

我错过了什么?

4

1 回答 1

1

对于您的问题..

[2]:*星频道是每个文档自动添加到该频道的频道。例如,来宾用户将被授予 * 星号频道,这为您提供开放式访问权限,因此任何获得 *(星号)的用户都将能够看到系统中的所有内容。

[3]:您不需要启用 CORS,因为同步网关与您的 web 应用程序在同一个域上运行。启用 CORS 允许 Web 应用程序访问其他域而不是源域上的资源。

LoginOrigin列表保护对_session_facebook端点的访问。

[4]:要复制您的数据,app.js您将在文件中定义一个用于同步的 URL 变量,例如:

var SYNC_GATEWAY_URL = 'http://127.0.0.1:4984/prospect/';
于 2015-09-19T01:14:42.843 回答