You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
};
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:
The expression:
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.
The text was updated successfully, but these errors were encountered: