typo and bugfixes

This commit is contained in:
AJ ONeal 2018-06-16 01:47:32 +00:00
parent 8fbd49f0e6
commit 58ed4baff1
2 changed files with 7 additions and 5 deletions

View File

@ -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();
});
});

View File

@ -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);