Skip to content

Commit d600426

Browse files
tlvinceptitjes
authored andcommitted
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
1 parent 7f44c9e commit d600426

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import urlJoin from 'url-join';
55
function getBaseUrl(db) {
66
if (typeof db.getUrl === 'function') { // pouchdb pre-6.0.0
77
return db.getUrl().replace(/[^/]+\/?$/, '');
8+
} else if (db.__opts && db.__opts.prefix) { // PouchDB.defaults
9+
return db.__opts.prefix;
810
} else { // pouchdb post-6.0.0
911
return db.name.replace(/[^/]+\/?$/, '');
1012
}

0 commit comments

Comments
 (0)