From d600426aaafa190337b4876186646ed29936d0b1 Mon Sep 17 00:00:00 2001 From: Tom Vincent Date: Wed, 15 Nov 2017 10:46:55 +0000 Subject: [PATCH] fix(urls): respect DB prefix for base URL if set If [PouchDB.defaults][1] is used, its options are attached to `__.opts`. In the case of `PouchDB.defaults({prefix: ''})`: > `prefix` appends a prefix to the database name and can be helpful for > URL-based or file-based LevelDOWN path names. For example: `{prefix: 'https://example.com/', name: 'test'}` would produce a DB "name" of `https://example.com/test`. Before, prefix was not respected. Closes #158. Connects #160. [1]: https://pouchdb.com/api.html#defaults --- src/utils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils.js b/src/utils.js index 69849d8..a32d417 100644 --- a/src/utils.js +++ b/src/utils.js @@ -5,6 +5,8 @@ import urlJoin from 'url-join'; function getBaseUrl(db) { if (typeof db.getUrl === 'function') { // pouchdb pre-6.0.0 return db.getUrl().replace(/[^/]+\/?$/, ''); + } else if (db.__opts && db.__opts.prefix) { // PouchDB.defaults + return db.__opts.prefix; } else { // pouchdb post-6.0.0 return db.name.replace(/[^/]+\/?$/, ''); }