From 08ba95576d45f8d26074d9b975cc4f97150f4953 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 18 Feb 2017 15:27:08 -0500 Subject: [PATCH] move request to utils module --- lib/services.js | 10 +++++----- lib/utils.js | 10 +++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/services.js b/lib/services.js index 158ee0afe..79562c3b4 100644 --- a/lib/services.js +++ b/lib/services.js @@ -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); }); diff --git a/lib/utils.js b/lib/utils.js index 5cd619e8e..df0e2162e 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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 };