Snippets

Popina Sync Gateway Config File Channels 104.155.33.203

You are viewing an old version of this snippet. View the current version.
Revised by Thomas Hebert 7a6fa3b
{
 "interface":":4984",
 "adminInterface":":4985",
 "log": ["*"],
   "databases": {
    "database": {
     "server":"http://104.155.33.203:8091/",
     "bucket":"default",
     "users": {
      "GUEST": {"disabled": false, "admin_channels": ["*"]}
      },
      "sync":`
      function (doc, oldDoc) {
     if (!doc.owner) throw({forbidden : "Documents must have a owner"});

     var webChannelForOwner = 'webFor_' + doc.owner;
     var mobileChannelForOwner = 'mobileFor_' + doc.owner;
     var restaurantForOwner = 'restaurantFor_' + doc.owner;
     var liveTillsForOwner = 'liveTillsFor_' + doc.owner;
     var pausedTillsForOwner = 'pausedTillsFor_' + doc.owner;
     var statsTillsForOwner = 'statsTillsFor_' + doc.owner;

     
     var channels = [mobileChannelForOwner, webChannelForOwner];

     var restaurantTypes = ['Restaurant'];

     // route channels
     if (restaurantTypes.indexOf(doc.type) !== -1) {
         channels.push(restaurantForOwner);
     }
     else {
         if (doc.status === 0) {
              channels.push(liveTillsForOwner);
         }
         else if (doc.status === 1) {
              channels.push(pausedTillsForOwner);
         }
         else {
              channels.push(statsTillsForOwner);
         }         
     }

     channel(channels);
}
`
   }
 }
}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.