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

View File

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