Skip to content

Instantly share code, notes, and snippets.

@adamcfraser
Last active October 31, 2016 22:02
Show Gist options
  • Save adamcfraser/a436ab31cf52b1139502bd946d135759 to your computer and use it in GitHub Desktop.
Save adamcfraser/a436ab31cf52b1139502bd946d135759 to your computer and use it in GitHub Desktop.
Targeting Sync Gateway cookie to path
// Set a Sync Gateway session cookies targeting specific paths
cookie1String = "SyncGatewaySession=3cad4b95524179bf144fe0d92b8f09877bb86bf5;path=/db1/";
cookie2String = "SyncGatewaySession=ead9488883b4e48f3f6140da212ffb45cdcd3e81;path=/db2/";
document.cookie = cookie1String;
document.cookie = cookie2String;
// Attempt to connect to db1.
var db1Req = new XMLHttpRequest();
db1Req.open("GET", "http://localhost:4984/db1/",false);
db1Req.send();
console.log("db1Req response:" + db1Req.responseText);
// Attempt to connect to db2.
var db2Req = new XMLHttpRequest();
db2Req.open("GET", "http://localhost:4984/db2/",false);
db2Req.send();
console.log("db2Req response:" + db2Req.responseText);
Adams-MacBook-Pro:bin adam$ http POST localhost:4985/db2/_session name=adam_2 password=5678
HTTP/1.1 200 OK
Content-Length: 140
Content-Type: application/json
Date: Mon, 31 Oct 2016 21:36:01 GMT
Server: Couchbase Sync Gateway/1.4 branch/master commit/e61729d+CHANGES
{
"cookie_name": "SyncGatewaySession",
"expires": "2016-11-01T14:36:01.283307232-07:00",
"session_id": "ead9488883b4e48f3f6140da212ffb45cdcd3e81"
}
Adams-MacBook-Pro:bin adam$ http POST localhost:4985/db1/_session name=adam_1 password=1234
HTTP/1.1 200 OK
Content-Length: 140
Content-Type: application/json
Date: Mon, 31 Oct 2016 21:59:02 GMT
Server: Couchbase Sync Gateway/1.4 branch/master commit/e61729d+CHANGES
{
"cookie_name": "SyncGatewaySession",
"expires": "2016-11-01T14:59:02.874239603-07:00",
"session_id": "3cad4b95524179bf144fe0d92b8f09877bb86bf5"
}
{
"interface":":4984",
"log":["*"],
"databases": {
"db1": {
"server": "http://localhost:8091",
"bucket": "bucket-1",
"users": {
"adam_1": {"password":"1234"}
}
},
"db2": {
"server": "http://localhost:8091",
"bucket": "bucket-2",
"users": {
"adam_2": {"password":"5678"}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment