You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, express-pouchdb does not handle sources and targets in any form other than a url. However, CouchDB specifies three ways to provide authentication for the replication route, two of which provide source and target as objects that are unhandled, so attempting to use these alternate forms of authentication cause the PouchDB server to throw a 500 error. I fixed this by replacing the source and target with PouchDB objects generated by req.PouchDB.new, which handles these forms of authentication. Is this the right way to go about this? If so, I'll make a PR and link it here.
Reproducible setup and test:
constaxios=require("axios");constimportFresh=require("import-fresh");constbtoa=require("btoa");/** * Creates an in-memory PouchDB server, a PouchDB object to access it, and * expose the server on localhost:port. * * @param {number} port - the port at which the in-memory server should be * made accessible. * * @returns {PouchDB} a PouchDB object to access the in-memory PouchDB server */functionpouchDBMemoryServer(username,password,port){// we need to disable caching of required modules to create separate pouchdb// server instancesvarInMemPouchDB=importFresh("pouchdb").defaults({db: importFresh("memdown"),});constapp=importFresh("express-pouchdb")(InMemPouchDB,{inMemoryConfig: true,});// add adminapp.couchConfig.set("admins",username,password,()=>{});app.listen(port);returnInMemPouchDB;}asyncfunctiontestIt(){// create two in-memory PouchDB serversletsourcePort=5984;lettargetPort=5985;letusername="username";letpassword="password";letsourceInstance=pouchDBMemoryServer(username,password,sourcePort);lettargetInstance=pouchDBMemoryServer(username,password,targetPort);// create a database in the source instanceletdbName="u-test";letdb=newsourceInstance(dbName);awaitdb.put({_id: "0",exampleDoc: "test"});// create basic authorization as base64 string. Note that the _replicate route// could also take this as { auth: { username, password }}constauthOpts={headers: {Authorization: "Basic "+btoa(`${username}:${password}`),},};// ensure database is presentawaitaxios.get(`http://localhost:${sourcePort}/${dbName}`,authOpts).then((r)=>console.log(r.status,r.statusText,r.data));// attempt to replicateawaitaxios.post(`http://localhost:${sourcePort}/_replicate`,{source: {url: `http://localhost:${sourcePort}/_replicate/${dbName}`,
...authOpts,},target: {url: `http://localhost:${targetPort}/_replicate/${dbName}`,
...authOpts,},create_target: true,continuous: true,},authOpts).then((r)=>console.log(r.data)).catch((err)=>console.log(err.status));}awaittestIt();
Currently, express-pouchdb does not handle sources and targets in any form other than a url. However, CouchDB specifies three ways to provide authentication for the replication route, two of which provide source and target as objects that are unhandled, so attempting to use these alternate forms of authentication cause the PouchDB server to throw a 500 error. I fixed this by replacing the source and target with PouchDB objects generated by req.PouchDB.new, which handles these forms of authentication. Is this the right way to go about this? If so, I'll make a PR and link it here.
Reproducible setup and test:
Which throws:
But after applying the below diff (generated by patch-package), everything works as expected:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: