mirror of https://github.com/embarklabs/embark.git
refactor httpGet
This commit is contained in:
parent
e88b51bdfd
commit
301ba94ef6
|
@ -200,29 +200,23 @@ class Engine {
|
||||||
//Ideally this method should be in an IPFS API JSONRPC wrapper
|
//Ideally this method should be in an IPFS API JSONRPC wrapper
|
||||||
//The URL should also be flexible to accept non-default IPFS url
|
//The URL should also be flexible to accept non-default IPFS url
|
||||||
self.logger.trace("Checking IPFS version...");
|
self.logger.trace("Checking IPFS version...");
|
||||||
utils.httpGet('http://' + host + ':' + port + '/api/v0/version', function (res) {
|
utils.httpGet('http://' + host + ':' + port + '/api/v0/version', function (err, body) {
|
||||||
let body = '';
|
if (err) {
|
||||||
res.on('data', function (d) {
|
|
||||||
body += d;
|
|
||||||
});
|
|
||||||
res.on('end', function () {
|
|
||||||
try {
|
|
||||||
let parsed = JSON.parse(body);
|
|
||||||
if (parsed.Version) {
|
|
||||||
return cb({name: ("IPFS " + parsed.Version), status: 'on'});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return cb({name: "IPFS ", status: 'on'});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
return cb({name: "IPFS ", status: 'off'});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
res.on('error', function (err) {
|
|
||||||
self.logger.trace("Check IPFS version error: " + err);
|
self.logger.trace("Check IPFS version error: " + err);
|
||||||
return cb({name: "IPFS ", status: 'off'});
|
return cb({name: "IPFS ", status: 'off'});
|
||||||
});
|
}
|
||||||
|
try {
|
||||||
|
let parsed = JSON.parse(body);
|
||||||
|
if (parsed.Version) {
|
||||||
|
return cb({name: ("IPFS " + parsed.Version), status: 'on'});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return cb({name: "IPFS ", status: 'on'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return cb({name: "IPFS ", status: 'off'});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -33,7 +33,18 @@ function checkIsAvailable(url, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function httpGet(url, callback) {
|
function httpGet(url, callback) {
|
||||||
return http.get(url, callback);
|
http.get(url, function(res) {
|
||||||
|
let body = '';
|
||||||
|
res.on('data', function (d) {
|
||||||
|
body += d;
|
||||||
|
});
|
||||||
|
res.on('end', function () {
|
||||||
|
callback(null, body);
|
||||||
|
});
|
||||||
|
res.on('error', function (err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function httpsGet(url, callback) {
|
function httpsGet(url, callback) {
|
||||||
|
@ -45,6 +56,9 @@ function httpsGet(url, callback) {
|
||||||
res.on('end', function () {
|
res.on('end', function () {
|
||||||
callback(null, body);
|
callback(null, body);
|
||||||
});
|
});
|
||||||
|
res.on('error', function (err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
0 info it worked if it ends with ok
|
||||||
|
1 verbose cli [ '/Users/iurimatias/.nvm/versions/node/v6.9.5/bin/node',
|
||||||
|
1 verbose cli '/Users/iurimatias/.nvm/versions/node/v6.9.5/bin/npm',
|
||||||
|
1 verbose cli 'run',
|
||||||
|
1 verbose cli 'fulltest' ]
|
||||||
|
2 info using npm@3.10.10
|
||||||
|
3 info using node@v6.9.5
|
||||||
|
4 verbose stack Error: missing script: fulltest
|
||||||
|
4 verbose stack at run (/Users/iurimatias/.nvm/versions/node/v6.9.5/lib/node_modules/npm/lib/run-script.js:151:19)
|
||||||
|
4 verbose stack at /Users/iurimatias/.nvm/versions/node/v6.9.5/lib/node_modules/npm/lib/run-script.js:61:5
|
||||||
|
4 verbose stack at /Users/iurimatias/.nvm/versions/node/v6.9.5/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5
|
||||||
|
4 verbose stack at checkBinReferences_ (/Users/iurimatias/.nvm/versions/node/v6.9.5/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45)
|
||||||
|
4 verbose stack at final (/Users/iurimatias/.nvm/versions/node/v6.9.5/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3)
|
||||||
|
4 verbose stack at then (/Users/iurimatias/.nvm/versions/node/v6.9.5/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5)
|
||||||
|
4 verbose stack at /Users/iurimatias/.nvm/versions/node/v6.9.5/lib/node_modules/npm/node_modules/read-package-json/read-json.js:243:12
|
||||||
|
4 verbose stack at /Users/iurimatias/.nvm/versions/node/v6.9.5/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
|
||||||
|
4 verbose stack at tryToString (fs.js:455:3)
|
||||||
|
4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)
|
||||||
|
5 verbose cwd /Users/iurimatias/Projects/embark-framework/test_app
|
||||||
|
6 error Darwin 16.7.0
|
||||||
|
7 error argv "/Users/iurimatias/.nvm/versions/node/v6.9.5/bin/node" "/Users/iurimatias/.nvm/versions/node/v6.9.5/bin/npm" "run" "fulltest"
|
||||||
|
8 error node v6.9.5
|
||||||
|
9 error npm v3.10.10
|
||||||
|
10 error missing script: fulltest
|
||||||
|
11 error If you need help, you may report this error at:
|
||||||
|
11 error <https://github.com/npm/npm/issues>
|
||||||
|
12 verbose exit [ 1, true ]
|
Loading…
Reference in New Issue