Merge pull request #222 from nogueian/develop

Implemented logic to show version of the connected IPFS node
This commit is contained in:
Iuri Matias 2017-02-23 19:42:29 -05:00 committed by GitHub
commit c35735d5b8
1 changed files with 29 additions and 5 deletions

View File

@ -1,6 +1,6 @@
var Web3 = require('web3'); var Web3 = require('web3');
var async = require('async'); var async = require('async');
var http = require('http');
var utils = require('./utils.js'); var utils = require('./utils.js');
var ServicesMonitor = function(options) { var ServicesMonitor = function(options) {
@ -60,12 +60,36 @@ ServicesMonitor.prototype.check = function() {
utils.checkIsAvailable('http://localhost:5001', function(available) { utils.checkIsAvailable('http://localhost:5001', function(available) {
if (available) { if (available) {
result.push('IPFS'.green); //Ideally this method should be in an IPFS API JSONRPC wrapper
} else { //The URL should also be flexible to accept non-default IPFS url
result.push('IPFS'.red); self.logger.trace("Checking IPFS version...");
http.get('http://localhost:5001/api/v0/version', function(res) {
var body = '';
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
var parsed = JSON.parse(body);
if(parsed.Version){
result.push(("IPFS " + parsed.Version).green);
}
else{
result.push("IPFS".green);
} }
callback(null, result); callback(null, result);
}); });
res.on('error', function(err) {
self.logger.trace("Check IPFS version error: " + err);
result.push("IPFS".green);
callback(null, result);
});
});
}
else {
result.push('IPFS'.red);
callback(null, result);
}
});
}, },
function checkDevServer(result, callback) { function checkDevServer(result, callback) {
self.logger.trace('checkDevServer'); self.logger.trace('checkDevServer');