0
votes

I am keen on using PouchDB in browser memory for an Angular application. This PouchDB will replicate from a remote LevelDB database that is fed key-value pairs from an algorithm. So, on the remote end, I would install PouchDB-Server. On the local end, I would do the following (as described here) on a node prompt.

var localDB = new PouchDB('mylocaldb')
var remoteDB = new PouchDB('https://remote-ip-address:5984/myremotedb')
localDB.sync(remoteDB, {
  live: true
}).on('change', function (change) {
  // yo, something changed!
}).on('error', function (err) {
  // yo, we got an error! (maybe the user went offline?)
});

How do we start a PouchDB instance that supports TLS for live replication as described in the snippet above? How do I start a PouchDB instance that supports TLS for live replication?

2

2 Answers

0
votes

So after some more searching, it is clear from this topic, HTTPS is not supported for PocuhDB-Server.

0
votes

Sorry, I misunderstood your question. I thought you intend to connect to a CouchDB server with PouchDB through HTTPS. Therefore, the following answer actually doesn't answer your question.


I created a server.js file like below to communicate with my CouchDB through HTTPS. Please note that the SSL certificate is (in my case) self-signed, and also CouchDB listens by default on port 6984 in the case of TLS:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; // Ignore rejection, becasue CouchDB SSL certificate is self-signed

//import PouchDB from 'pouchdb'
const PouchDB = require('pouchdb')
const db = new PouchDB('https://admin:****@192.168.1.106:6984/reproduce')

db.allDocs({
    include_docs: true,
    attachments: false
}).then(function (result) {
    // handle result
    console.log(result)
}).catch(function (err) {
    console.log(err);
});

I'm running the above file with $ node server.js and I'm getting the expected results:

$ node server.js 
{ total_rows: 3,
  offset: 0,
  rows: 
   [ { id: '5d6590d3-41c7-4011-be5d-b21f80079ae5',
       key: '5d6590d3-41c7-4011-be5d-b21f80079ae5',
       value: [Object],
       doc: [Object] },
     { id: 'ec6a36d1-952e-4d86-9865-3587c6079fb5',
       key: 'ec6a36d1-952e-4d86-9865-3587c6079fb5',
       value: [Object],
       doc: [Object] },
     { id: 'f508e7aa-b4dc-42fc-96be-b7c1ffa54172',
       key: 'f508e7aa-b4dc-42fc-96be-b7c1ffa54172',
       value: [Object],
       doc: [Object] } ] }

I created the above code with NodeJS on server-side. However, if you want to communicate with CouchDB through HTTPS inside the browser, i.e. on client-side, you have to enable CORS on CouchDB.