I am trying to set up pouchDB syncing but i'm having trouble connecting to couchDB remotely... I have followed these instructions from couchDB to install on my ubunto server - which is managed with laravel forge...though this project itself is not using laravel (just a regular html file)
Everything has installed correctly, with all expected responses
If i run: curl localhost:5984
I get: {"couchdb":"Welcome","uuid":"*******************","version":"1.6.1","vendor":{"version":"14.04","name":"Ubuntu"}}
I ran: npm install -g add-cors-to-couchdb and add-cors-to-couchdb
And I am not getting any cross-origin errors
But if i try and go to http://178.xx.xxx.xxx:5984/_utils it just hangs?
When using the following code:
var localdb = new PouchDB('messages');
var remotedb = new PouchDB('http://178.xx.xx.xx:5984/messages');
localdb.sync(remotedb, {live: true});
I get:
Unhandled promise rejection
Promise
{
[[PromiseStatus]]: "rejected",
[[PromiseValue]]: o
}
__proto__: Promise
[[PromiseStatus]]: "rejected"
[[PromiseValue]]: o
error: true
message: "Database encountered an unknown error"
name: "unknown_error"
status: 500
(taken from chrome)
Any ideas why I'm getting this error? It seems to be timing out.....any ideas why it would be doing this?
Also if I use: ssh -L5984:127.0.0.1:5984 [email protected]
and then go to http://localhost:5984/_utils/ it works fine
Also replacing the remote address with http://localhost:5984/messages also makes the syncing work
While using this I have also checked everything has installed correctly using the "Verify Installation" and it comes back with "Your installation looks fine. Time to Relax."
Strange!
So does anyone have any ideas why I can't connect to the couchDB remotely?
Any help would be much appreciated!
Thanks, Dave
It sounds like you need to modify the local.ini file for your CouchDB to allow access from more IPs than just localhost.
Check your local.ini for this section:
[httpd]
;port = 5984
;bind_address = 127.0.0.1
Change this to:
[httpd]
;port = 5984
bind_address = 0.0.0.0
Edit: an even easier solution is to just set up your Nginx/Apache proxy to route http://example.com/couchdb to localhost:5984. Here's the Nginx config I use:
location /couchdb {
rewrite /couchdb(.*) $1 break;
proxy_pass http://127.0.0.1:5984;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With