You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by ro...@apache.org on 2015/07/12 13:55:35 UTC
[15/50] couchdb-nano git commit: Introduce parseUrl flag to prevent
db extraction
Introduce parseUrl flag to prevent db extraction
When the `parseUrl` flag is set to `false` (default it `true`) `url` will not
be parsed but will be considered the root of the CouchDB server and Nanos
server api gets returned.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-nano/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-nano/commit/0b34fa1d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-nano/tree/0b34fa1d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-nano/diff/0b34fa1d
Branch: refs/heads/master
Commit: 0b34fa1d34eed53f17af10dcd999ddca76cd1f0d
Parents: ff989b3
Author: Johannes J. Schmidt <sc...@netzmerk.com>
Authored: Thu Jan 29 09:52:36 2015 +0100
Committer: Johannes J. Schmidt <jo...@die-tf.de>
Committed: Thu Feb 26 12:59:23 2015 +0100
----------------------------------------------------------------------
README.md | 12 ++++++++++++
lib/nano.js | 29 +++++++++++++++++++----------
tests/integration/shared/config.js | 14 ++++++++++++++
3 files changed, 45 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/0b34fa1d/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 5fb41b3..4376a42 100644
--- a/README.md
+++ b/README.md
@@ -165,6 +165,18 @@ var db = require('nano')(
```
Please check [request] for more information on the defaults. They support features like cookie jar, proxies, ssl, etc.
+You can tell nano to not parse the url (maybe the server is behind a proxy, is accessed through a rewrite rule or other):
+
+```js
+// nano does not parse the url and return the server api
+// "http://localhost:5984/prefix" is the CouchDB server root
+var couch = require('nano')(
+ { "url" : "http://localhost:5984/prefix"
+ "parseUrl" : false
+ });
+var db = couch.use('foo')
+```
+
### pool size and open sockets
a very important configuration parameter if you have a high traffic website and are using nano is setting up the `pool.size`. by default, the node.js http global agent (client) has a certain size of active connections that can run simultaneously, while others are kept in a queue. pooling can be disabled by setting the `agent` property in `requestDefaults` to false, or adjust the global pool size using:
http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/0b34fa1d/lib/nano.js
----------------------------------------------------------------------
diff --git a/lib/nano.js b/lib/nano.js
index f780a5e..f63a1ed 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -31,6 +31,23 @@ module.exports = exports = nano = function dbScope(cfg) {
request.defaults(cfg.requestDefaults);
var followAgent = (typeof cfg.follow === 'function') ? cfg.follow : follow;
var log = typeof cfg.log === 'function' ? cfg.log : logger(cfg);
+ var parseUrl = 'parseUrl' in cfg ? cfg.parseUrl : true;
+
+ function maybeExtractDatabaseComponent() {
+ if (!parseUrl) {
+ return;
+ }
+
+ var path = u.parse(cfg.url);
+ var pathArray = path.pathname.split('/').filter(function(e) { return e; });
+ var db = pathArray.pop();
+ var rootPath = path.pathname.replace(/\/?$/, '/..');
+
+ if (db) {
+ cfg.url = u.resolve(cfg.url, rootPath).replace(/\/?$/, '');
+ return db;
+ }
+ }
function relax(opts, callback) {
if (typeof opts === 'function') {
@@ -716,17 +733,9 @@ module.exports = exports = nano = function dbScope(cfg) {
followUpdates: followUpdates
});
- var path = u.parse(cfg.url);
- var pathArray = path.pathname.split('/').filter(function(e) { return e; });
- var db = pathArray.pop();
- var rootPath = path.pathname.replace(/\/?$/, '/..');
-
- if (db) {
- cfg.url = u.resolve(cfg.url, rootPath).replace(/\/?$/, '');
- return docModule(db);
- }
+ var db = maybeExtractDatabaseComponent();
- return serverScope;
+ return db ? docModule(db) : serverScope;
};
/*
http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/0b34fa1d/tests/integration/shared/config.js
----------------------------------------------------------------------
diff --git a/tests/integration/shared/config.js b/tests/integration/shared/config.js
index 43c1cff..23ffd8b 100644
--- a/tests/integration/shared/config.js
+++ b/tests/integration/shared/config.js
@@ -77,6 +77,20 @@ it('should be able to parse urls', function(assert) {
assert.end();
});
+it('should not parse urls when parseURL flag set to false', function(assert) {
+ var url = 'http://someurl.com/path';
+
+ assert.equal(
+ Nano({
+ url: url,
+ parseUrl: false
+ }).config.url,
+ url,
+ 'the untouched url');
+
+ assert.end();
+});
+
it('should accept and handle customer http headers', function(assert) {
var nanoWithDefaultHeaders = Nano({
url: helpers.couch,