Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Agent.prototype.failCheck = function (checkId, opts, done) {
Agent.prototype.registerService = function (service, opts, done) {
if ('function' == typeof opts) done = opts, opts = null;

this.requestor.get('service/register', service, opts, done);
this.requestor.put('service/register', service, opts, done);
};

/**
Expand Down
14 changes: 13 additions & 1 deletion lib/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ module.exports = Catalog;
/**
* Catalog constructor.
*
* @param {Consul} consol
* @param {Consul} consul
* @constructor
*/

function Catalog (consul) {
this.requestor = new Requestor('catalog', consul);
}

/**
* Lists the services in a catalog.
*
* @param {Object} [opts]
* @param {Function} done
*/
Catalog.prototype.services = function(opts, done) {
if ('function' == typeof opts) done = opts, opts = null;

this.requestor.get('services', opts, done);
};

/**
* Lists the nodes in a given service.
*
Expand Down
4 changes: 3 additions & 1 deletion lib/kv.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ KV.prototype.get = function (key, opts, done) {
if (!items) return done(null, items);

done(null, items.map(function (item) {
// do not try to base64 decode empty items e.g. nulls
var val = (item['Value']) ? new Buffer(item['Value'], 'base64').toString('utf8') : item['Value'];
return {
createIndex: item['CreateIndex'],
modifyIndex: item['ModifyIndex'],
key: item['Key'],
flags: item['Flags'],
value: new Buffer(item['Value'], 'base64').toString('utf8')
value: val
};
}));
});
Expand Down
12 changes: 9 additions & 3 deletions lib/requestor.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,19 @@ Requestor.prototype.get = function (path, opts, done) {
*/

Requestor.prototype.put = function (path, data, opts, done) {
this.request({
var req = {
method: 'PUT',
url: this.urlFor(path),
qs: opts,
body: data,
encoding: 'utf8'
}, done);
};

if (data && typeof data == 'object')
req.json = data;
else
req.body = data;

this.request(req, done);
};

/**
Expand Down