CORS issue with PouchDB and Couch Sync Gateway

Hi all,

I have already posted this query in the Couchbase Server category. However, it has been suggested to me that it would be more suited in the Mobile category, so resubmitting it there.

I wonder if someone could help me with Cors? I’m using Couchbase set up on the default port 8091. I’m talking to it via PouchDB, and syncing with couch-sync-gateway.

In my app I get the message “PouchDB error: the remote database does not seem to have CORS enabled. To fix this, please enable CORS”. Following the message, I’ve tried to run the add-cors-to-couchdb script from PouchDB to fix this, but this doesn’t work as it’s written for CouchDB, not Couchbase. There isn’t a CouchBase version as far as I know.

I have added the Cors section to the sync gateway config file but the message is still displayed. It does actual still sync when I enable the guest user but I can’t get it to work when trying to add user login.

Do I need to enable Cors on the Couchbase side and, if so, how do I do this?

Thanks,
Giles

@giles

Can you post your Sync Gateway config file, it will make it easier to help debug your issue.

Hi @andy and all,

Apologies for not replying earlier and posting the config file. I believe I have resolved this, at least for now. The main reason that the cors message was appearing is because I was either listening before I was syncing or stopping syncing before I stopped listening. So the PouchDB side was listening but wasn’t syncing to couch-sync-gateway yet.

The problem where I said that I couldn’t get it to work when trying to add user login is because I wasn’t specifying “admin_channels = [*]” when specifying a user. This was in the setup for the guest user which is why it was working before I tried to add authentication. When it wasn’t syncing properly (due to the channels, or because I wasn’t authenticating the user properly) I was also sometimes getting the CORS error.

Both of these issues have been bugging me for a few days so Im glad I’ve finally got to the bottom of them.

Thanks,
Giles