Skip to content

Commit

Permalink
fix(urls): respect DB prefix for base URL if set
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tlvince authored and ptitjes committed Nov 17, 2017
1 parent 7f44c9e commit d600426
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(/[^/]+\/?$/, '');
}
Expand Down

0 comments on commit d600426

Please sign in to comment.