From f9d23f39ff84436daf9e360724750b7097c1622c Mon Sep 17 00:00:00 2001 From: ktmud Date: Fri, 23 Dec 2011 14:01:09 +0800 Subject: [PATCH 1/2] support for couchdb in a subdirectory --- lib/cradle.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/cradle.js b/lib/cradle.js index 7700ff6..b3b7512 100644 --- a/lib/cradle.js +++ b/lib/cradle.js @@ -67,6 +67,13 @@ cradle.Connection = function Connection(/* variable args */) { this.host = this.host.replace(protocolPattern, ''); } + if (this.host.indexOf('/') != -1) { + var tmp = this.host.split('/'); + this.host = tmp.shift(); + this.path_prefix = '/' + tmp.join('/'); + } + + if (this.protocol === 'https') this.options.secure = true; if (this.auth && this.auth.user) { // Deprecation warning @@ -110,6 +117,7 @@ cradle.Connection.prototype.rawRequest = function (method, path, options, data, } path = (path || '/').replace(/https?:\/\//, '').replace(/\/{2,}/g, '/'); + if (this.path_prefix) { path = this.path_prefix + path } if (path.charAt(0) !== '/') { path = '/' + path } if (options && Object.keys(options).length) { @@ -685,3 +693,5 @@ cradle.merge = function (target) { }); return target; } + + From 52752106f1f88484af98dcfb913980c725ffb189 Mon Sep 17 00:00:00 2001 From: ktmud Date: Fri, 23 Dec 2011 14:09:18 +0800 Subject: [PATCH 2/2] setting up `example.com/couch` will now work --- lib/cradle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cradle.js b/lib/cradle.js index b3b7512..b0e5f55 100644 --- a/lib/cradle.js +++ b/lib/cradle.js @@ -117,8 +117,8 @@ cradle.Connection.prototype.rawRequest = function (method, path, options, data, } path = (path || '/').replace(/https?:\/\//, '').replace(/\/{2,}/g, '/'); - if (this.path_prefix) { path = this.path_prefix + path } if (path.charAt(0) !== '/') { path = '/' + path } + if (this.path_prefix) { path = this.path_prefix + path } if (options && Object.keys(options).length) { for (var k in options) {