5

I need help syncing PouchDB with Couchbase Sync Gateway.

I keep getting the following error that points to a CORS problem, but I've configured Couchbase Sync Gateway (CSG) for CORS according to their documentation.

XMLHttpRequest cannot load http://localhost:4985/test-database/.
No 'Access-Control-Allow-Origin'header is present on the requested
resource. Origin 'http://localhost:3000' is therefore not 
allowed access.

I've tried the following config file per the CSG docs:

http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/sync-gateway/configuring-sync-gateway/config-properties/index.html

{
  "log": ["HTTP+"],
  "CORS": {
    "origin":["http://localhost:3000"],
    "loginOrigin":["http://localhost:3000"],
    "headers":["Content-Type"],
    "maxAge": 1728000
  },
  "databases": {
    "test-database": {
      "server": "walrus:",
      "users": { "GUEST": {"disabled": false, "admin_channels": ["*"] } }
    }
  }
}

I've tried other config files as well from the Couchbase blog, but none of them work! Any help with this will be greatly appreciated!

Corey Quillen
  • 1,566
  • 4
  • 24
  • 52
  • Looks like the only difference is port number 8k vs 3k... Can you use curl/postman to call http://localhost:3000 - to see if cors header is in result? If so - problem is with PouchDB. Other case is that your configuration was somehow ignored. I know that restarting/redoing is silly advise, or perhaps you did that. But just in case - can you confirm that? :) – Michał Zaborowski Apr 26 '16 at 21:39

2 Answers2

5

It looks like you're trying to hit the Sync Gateway admin port, which doesn't support CORS, as far as I know. Have you tried targeting the public port (4984)?

adamcf
  • 201
  • 1
  • 1
-1

it's because you need to enable CORS on CouchDB. Otherwise, your scripts can only access the server database if they're served from the same origin — the protocol (ex: http://, https://), domain, and port number must match.

You can enable CORS in CouchDB using curl or the Futon web interface, but we've saved you some time by making a Node script called add-cors-to-couchdb. Just run:

npm install -g add-cors-to-couchdb
add-cors-to-couchdb

for more info, refer the link
https://pouchdb.com/errors.html#no_access_control_allow_origin_header

ravindar
  • 406
  • 4
  • 13