Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra '/' when posting a document #190

Open
fourlincoln10 opened this issue Oct 3, 2012 · 3 comments
Open

Extra '/' when posting a document #190

fourlincoln10 opened this issue Oct 3, 2012 · 3 comments

Comments

@fourlincoln10
Copy link

While testing a function that posts a document to a database called 'v2', I found that cradle was posting to the url 'v2//'. I looked at the code (see below) and the issue is setting path to '/' in Database.post and then using join in Database.query:

/**
 * lib/cradle/database/document.js
 */

//
// POST a document, and write through cache
//
Database.prototype.post = function (doc, callback) {
    var cache = this.cache;
    this.query({
        method: 'POST', 
        path: '/',
        body: doc 
    }, function (e, res) {
        if (! e) { cache.save(res.id, cradle.merge({}, doc, { _id: res.id, _rev: res.rev })) }
        callback && callback(e, res);
    }); 
};


/**
 * lib/cradle/database/index.js
 */

// A wrapper around `Connection.request`,
// which prepends the database name.
Database.prototype.query = function (options, callback) { 
    options.path = [this.name, options.path].filter(Boolean).join('/');
    this.connection.request(options, callback);
};

The expression:

options.path = [this.name, options.path].filter(Boolean).join('/');

adds an extra '/' to the path.

Setting path to '' in Database.post seems to fix things, but I'm not sure if that will work in all scenarios.

@shashwat5
Copy link

Any progress on this?

@shashwat5
Copy link

Also happens when database.all() is used, url is database//all_docs

@Chima1707
Copy link

Any progress on this? am experiencing the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants