Android replication via Reverse Proxy

Hi,

I have following problem. We have couch DB on Server, but for outside we made apache reverse proxy and from outside our couch DB server visible as our.server.address/couchdb.

Replication from mobile Android device to to a database our.server.address/couchdb/mydatabase does not work. I looked into logs in Android Studio, and saw that couchbase lite does following:
GET our.server.address/couchdb/mydatabase/_session
Got error status: 404 for our.server.address/couchdb/mydatabase/_session
GET our.server.address/_session
connection refused

Which is of course wrong. If the logic is to make _session request to Couch DB instance, then the second request should be our.server.address/couchdb/_session.

I understand that in REST world we it is not clear that database instance under /couchdb, maybe should a new setting or property be introduced for that?

Currently we solved issue with a simple redirect in Apache Proxy from our.server.address/_session to our.server.address/couchdb/_session, but this is no good.

Thanks in advance

Hi @Alex_Dobrushin,

What’s the name of the Couchbase Lite database you’re replicating from?
From the logs it looks like in the first request, the database name is couchdb/mydatabase?

James

Hi,

I am trying to replicate from mobile device, where I am using couchbase lite 1.1.0 to Apache CouchDB 1.6.1

Apache Couch DB we installed on server, default installation is on port 5984, and we do not have free external IP address only for database. Thats why we make an Apache Reverse proxy, and our Database instance now redirected:

http://localhost:5984 -> https://www.company.net/couchdb

and https://www.company.net/couchdb/mydatabase is a database created in CouchDB which should be synchronised with DB on mobile.

Sorry if you asking how called my internal Database on mobile device - something different to “mydatabase”. Doees it makes any difference?

Sorry I got confused. I see what you mean now.
As you said above, having couchdb in the target url confuses the replicator to assume that couchdb is the database name when in fact it’s mydatabase.

I can’t think of another workaround than the one you explained, having a reverse proxy to rewrite /_session as /couchdb/_session.

James

But it is actually not good. Imagine I have one server where Apache Proxy to outside works, and two different internal servers where two CouchDB databases (let say UAT and Production).

So I have no chance to differentiate from requests if CBL will send GET to /_session.
I suppose this is a logic inside CBL, not couch DB, first GET request is sent to server/dbinstance/db/_session, second just to server/_session.

Would it be possible to implement like 2 options:

  • send second request to server/dbinstance, then to server/, so to each part of path until session will be created?
  • or make an additional setting (property) like DBInstance or what ever…

The REST replication API requires that the server be located at / and databases at /db. You can’t move the root of CouchDB to a subpath like /couchdb. That’s not a Couchbase Lite issue; I don’t think the CouchDB replicator will handle that either.