I'm trying to find a way to pass custom HTTP headers with ajax requests when syncing between a local pouch instance and a remote.
As best I can tell from reading the docs and perusing the source, it looks like you're able to do this if you're using pouch as a proxy to a remote, like this...
This works
var db = new PouchDB('http://foo.io/db/', {
ajax: { headers: { authorization: authenticationToken.get() } }
});
but, I'm not able to do the same if I'm creating a local database and syncing to a remote...
This ignores my header
var db = new PouchDB('MyLocalDb');
PouchDB.replicate('MyLocalDb', 'http://foo.io/db/', {
live: true,
ajax: { headers: { authorization: authenticationToken.get() } }
});
Am I overlooking something or is this not currently possible?
Thanks for your help, and thanks for making such an awesome open source project. :)
To specify options for the remote databases you can do
var db = new PouchDB('MyLocalDb');
var remote = new PouchDB('http://foo.io/db/', {
ajax: { headers: { authorization: authenticationToken.get() } }
});
db.replicate.to(remote, {live: true});
Any other questions feel free :) Thanks
Oh man, totally obvious now.
Thanks so much!
Sent from my iPhone
On Feb 27, 2016, at 1:21 PM, Dale Harvey [email protected] wrote:
To specify options for the remote databases you can do
var db = new PouchDB('MyLocalDb');
var remote = new PouchDB('http://foo.io/db/', {
ajax: { headers: { authorization: authenticationToken.get() } }
});
db.replicate.to(remote, {live: true});
Any other questions feel free :) Thanks—
Reply to this email directly or view it on GitHub.
After digging in a little more, I noticed that the headers still weren't being passed. I figured out why, and I just want to share it here in case anyone else stumbles upon it in the future.
The key line in the docs that I didn't notice is this:
_The remoteDB can either be a string or a PouchDB object_. If you have special ajax options on a remote database, you will want to use PouchDB objects instead of strings, so that the options are used.
I was passing the ajax headers into my local pouch instance when I created it, but when adding syncs I was passing the local db name rather than the PouchDb instance itself, so they were ignored.
Thanks again for the help.
Most helpful comment
After digging in a little more, I noticed that the headers still weren't being passed. I figured out why, and I just want to share it here in case anyone else stumbles upon it in the future.
The key line in the docs that I didn't notice is this:
I was passing the ajax headers into my local pouch instance when I created it, but when adding syncs I was passing the local db name rather than the PouchDb instance itself, so they were ignored.
Thanks again for the help.