当前位置: 动力学知识库 > 问答 > 编程问答 >

osx - How to establish connection between couchbase server and couchbase sync gateway in Mac OS?

问题描述:

Establishing connection between couchbase server and couchbase sync gateway in Mac OS -

$ ../sync_gateway

==== Couchbase Sync Gateway/1.0.4(34;04138fd) ====

Configured Go to use all 2 CPUs; `setenv GOMAXPROCS` to override this

Opening db /sync_gateway as bucket "sync_gateway", pool "default", server <walrus:>

Opening Walrus database sync_gateway on <walrus:>

Using default sync function `'channel(doc.channels)'` for database "sync_gateway"

Starting profile server on

***Starting admin server on 127.0.0.1:4985

Starting server on :4984 ...***

I created a config.json file and trying to connect it to that sever but its not happening by default its going to 127.0.0.1:4985

Can anyone help me out??

网友答案:

Add the following config value to your config.json file:

"adminInterface":"[YOUR_PREFERRED_IP_FOR_ADMIN_INTERFACE]:4985",

The adminInterface field let's the sync_gateway know on which IP:PORT to run the admin interface on.

Also, you need to tell sync_gateway where to fire the rest APIs for a bucket (todos in the sample below). As shown in the example below you can do that by adding "server": "http://[COUCHBASE_SERVER_IP]:8091", in the config for the database.

So,

  1. You will fire admin rest APIs on [YOUR_PREFERRED_IP_FOR_ADMIN_INTERFACE]:4985.
  2. And, sync_gateway will fire rest apis for CRUD operations for the "todos" bucket on [COUCHBASE_SERVER_IP]:8091.

Here is sample config file:

{
  "interface":"192.168.1.117:4984",
  "adminInterface":"127.0.0.1:4985",
  "log": ["CRUD", "REST+", "Access"],
  "facebook": { "register": true },
  "databases": {
    "todos": {
      "server": "http://[COUCHBASE_SERVER_IP]:8091",
      "users": {
        "GUEST": {"disabled": true}
      },
      "sync": 
    `
      function(doc, oldDoc) {
        // NOTE this function is the same across the iOS, Android, and PhoneGap versions.
        if (doc.type == "task") {
          if (!doc.list_id) {
            throw({forbidden : "Items must have a list_id"})
          }
          channel("list-"+doc.list_id);
        } else if (doc.type == "list") {
          channel("list-"+doc._id);
          if (!doc.owner) {
            throw({forbidden : "List must have an owner"})
          }
          if (oldDoc) {
            var oldOwnerName = oldDoc.owner.substring(oldDoc.owner.indexOf(":")+1);
            requireUser(oldOwnerName)
          }
          var ownerName = doc.owner.substring(doc.owner.indexOf(":")+1);
          access(ownerName, "list-"+doc._id);
          if (Array.isArray(doc.members)) {
            var memberNames = [];
            for (var i = doc.members.length - 1; i >= 0; i--) {
              memberNames.push(doc.members[i].substring(doc.members[i].indexOf(":")+1))
            };
            access(memberNames, "list-"+doc._id);
          }
        } else if (doc.type == "profile") {
          channel("profiles");
          var user = doc._id.substring(doc._id.indexOf(":")+1);

          if (user !== doc.user_id) {
            throw({forbidden : "Profile user_id must match docid : " + user + " : " + doc.user_id})
          }
          requireUser(user);
          access(user, "profiles"); // TODO this should use roles
        }
      }
    `
    }
  }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: