move request to utils module

This commit is contained in:
Iuri Matias 2017-02-18 15:27:08 -05:00
parent a25d225a8b
commit 08ba95576d
2 changed files with 14 additions and 6 deletions

View File

@ -1,6 +1,6 @@
var Web3 = require('web3'); var Web3 = require('web3');
var async = require('async'); var async = require('async');
var request = require('request'); var utils = require('./utils.js');
var ServicesMonitor = function(options) { var ServicesMonitor = function(options) {
this.logger = options.logger; this.logger = options.logger;
@ -57,11 +57,11 @@ ServicesMonitor.prototype.check = function() {
function checkIPFS(result, callback) { function checkIPFS(result, callback) {
self.logger.trace('checkIPFS'); self.logger.trace('checkIPFS');
request('http://localhost:5001', function(error, response, body) { utils.checkIsAvailable('http://localhost:5001', function(available) {
if (error) { if (available) {
result.push('IPFS'.red);
} else {
result.push('IPFS'.green); result.push('IPFS'.green);
} else {
result.push('IPFS'.red);
} }
callback(null, result); callback(null, result);
}); });

View File

@ -1,6 +1,7 @@
var path = require('path'); var path = require('path');
var grunt = require('grunt'); var grunt = require('grunt');
var merge = require('merge'); var merge = require('merge');
var request = require('request');
function joinPath() { function joinPath() {
return path.join.apply(path.join, arguments); return path.join.apply(path.join, arguments);
@ -18,10 +19,17 @@ function recursiveMerge(target, source) {
return merge.recursive(target, source); return merge.recursive(target, source);
} }
function checkIsAvailable(url, callback) {
request(url, function(error, response, body) {
callback(!error);
});
}
module.exports = { module.exports = {
joinPath: joinPath, joinPath: joinPath,
filesMatchingPattern: filesMatchingPattern, filesMatchingPattern: filesMatchingPattern,
fileMatchesPattern: fileMatchesPattern, fileMatchesPattern: fileMatchesPattern,
recursiveMerge: recursiveMerge recursiveMerge: recursiveMerge,
checkIsAvailable: checkIsAvailable
}; };