Skip to content

Instantly share code, notes, and snippets.

@PaulCapestany
Created April 3, 2013 06:43
Show Gist options
  • Save PaulCapestany/5298946 to your computer and use it in GitHub Desktop.
Save PaulCapestany/5298946 to your computer and use it in GitHub Desktop.
sync_gateway config file
{
"interface": ":4984",
"adminInterface": ":4985",
"log": ["CRUD", "Auth", "HTTP+"],
"databases": {
"sync_gateway": {
"server": "http://localhost:8091",
"bucket": "sync_gateway"
},
"another-app": {
"server": "http://localhost:8091",
"bucket": "another-app"
},
"couchchat": {
"server": "http://localhost:8091",
"bucket": "couchchat",
"users": {
"GUEST": {"disabled": true}
},
"sync": `
function(doc, oldDoc, userCtx, secObj) {
if (doc.channel_id) {
// doc belongs to a channel
channel("ch-"+doc.channel_id);
// this document describes a channel
if (doc.channel_id == doc._id) {
// magic document, treat it carefully
if (oldDoc && oldDoc.owners.indexOf(userCtx.name) == -1) {
throw({unauthorized:"you are not a channel owner"});
}
// grants access to the channel to all members and owners
var them = doc.owners.concat(doc.members);
access(doc.owners, "ch-"+doc._id);
access(doc.members, "ch-"+doc._id);
// notify members of the new channel
// TODO this can be removed once
// https://github.com/couchbaselabs/sync_gateway/issues/31
// is fixed
for (var i = 0; i < them.length; i++) {
channel("chs-"+them[i]);
};
}
}
if (doc.type == "profile") {
channel("profiles");
var user = doc._id.substring(doc._id.indexOf(":")+1);
access(user, "profiles");
// TODO remove when #31 is fixed
access(user, "chs-"+user);
}
}
`
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment