Browse files

Add pathname to URLs if db is provided.

  • Loading branch information...
1 parent 277b893 commit 0ab0054cae6c42d56501aa1e1b5a466cb90144be @efolio committed Nov 21, 2012
Showing with 16 additions and 5 deletions.
  1. +16 −5 nano.js
View
21 nano.js
@@ -1007,18 +1007,29 @@ module.exports = exports = nano = function database_module(cfg) {
path_array = path.pathname.split('/').filter(function(e) { return e; });
// nano('http://couch.nodejitsu.com/db1')
+ // nano({url: 'http://couch.nodejitsu.com/path', db: 'db1'})
// should return a database
// nano('http://couch.nodejitsu.com')
// should return a nano object
- if(path.pathname && path_array.length > 0) {
+ if (path.pathname && path_array.length > 0) {
+
auth = path.auth ? path.auth + '@' : '';
port = path.port ? ':' + path.port : '';
- db = path_array[0];
- cfg.url = u.format(
- {protocol:path.protocol,host: auth + path.hostname + port});
+ db = cfg.db ? cfg.db : path_array[0];
+
+ var format = {
+ protocol: path.protocol,
+ host: auth + path.hostname + port
+ };
+ if (cfg.db)
+ format.pathname = path.pathname + '/';
+
+ cfg.url = u.format(format);
+
return document_module(db);
}
- else { return public_functions; }
+ else
+ return public_functions;
};

0 comments on commit 0ab0054

Please sign in to comment.