From 58ed4baff15ffda15ca48c03ac97170b8ebb16b7 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 16 Jun 2018 01:47:32 +0000 Subject: [PATCH] typo and bugfixes --- bin/telebit.js | 7 ++++--- lib/cli-common.js | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/telebit.js b/bin/telebit.js index 2784f28..6462cc0 100755 --- a/bin/telebit.js +++ b/bin/telebit.js @@ -139,12 +139,12 @@ function askForConfig(answers, mainCb) { rl.question('relay [default: telebit.cloud]: ', function (relay) { // TODO parse and check https://{{relay}}/.well-known/telebit.cloud/directives.json if (!relay) { relay = 'telebit.cloud'; } - answers.relay = relay.trim(); - var urlstr = common.parseUrl(answers.relay) + common.apiDirectory; + relay = relay.trim(); + var urlstr = common.parseUrl(relay) + common.apiDirectory; common.urequest({ url: urlstr, json: true }, function (err, resp, body) { if (err) { console.error("[Network Error] Failed to retrieve '" + urlstr + "'"); - console.error(e); + console.error(err); askRelay(cb); return; } @@ -168,6 +168,7 @@ function askForConfig(answers, mainCb) { if (body.pair_request) { answers._can_pair = true; } + answers.relay = relay; cb(); }); }); diff --git a/lib/cli-common.js b/lib/cli-common.js index dd15b18..62b83ee 100644 --- a/lib/cli-common.js +++ b/lib/cli-common.js @@ -40,17 +40,18 @@ common.parseUrl = function (hostname) { common.apiDirectory = '_apis/telebit.cloud/index.json'; common.urequest = function (opts, cb) { + var https = require('https'); // request.js behavior: // encoding: null + json ? unknown // json => attempt to parse, fail silently // encoding => buffer.toString(encoding) // null === encoding => Buffer.concat(buffers) - https.get(opts, function (resp) { + https.get(opts.url, function (resp) { var encoding = opts.encoding; if (null === encoding) { resp._body = []; } else { - resp._body = ''; + resp.body = ''; } if (!resp.headers['content-length'] || 0 === parseInt(resp.headers['content-length'], 10)) { cb(resp);