typo and bugfixes
This commit is contained in:
parent
8fbd49f0e6
commit
58ed4baff1
|
@ -139,12 +139,12 @@ function askForConfig(answers, mainCb) {
|
||||||
rl.question('relay [default: telebit.cloud]: ', function (relay) {
|
rl.question('relay [default: telebit.cloud]: ', function (relay) {
|
||||||
// TODO parse and check https://{{relay}}/.well-known/telebit.cloud/directives.json
|
// TODO parse and check https://{{relay}}/.well-known/telebit.cloud/directives.json
|
||||||
if (!relay) { relay = 'telebit.cloud'; }
|
if (!relay) { relay = 'telebit.cloud'; }
|
||||||
answers.relay = relay.trim();
|
relay = relay.trim();
|
||||||
var urlstr = common.parseUrl(answers.relay) + common.apiDirectory;
|
var urlstr = common.parseUrl(relay) + common.apiDirectory;
|
||||||
common.urequest({ url: urlstr, json: true }, function (err, resp, body) {
|
common.urequest({ url: urlstr, json: true }, function (err, resp, body) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("[Network Error] Failed to retrieve '" + urlstr + "'");
|
console.error("[Network Error] Failed to retrieve '" + urlstr + "'");
|
||||||
console.error(e);
|
console.error(err);
|
||||||
askRelay(cb);
|
askRelay(cb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -168,6 +168,7 @@ function askForConfig(answers, mainCb) {
|
||||||
if (body.pair_request) {
|
if (body.pair_request) {
|
||||||
answers._can_pair = true;
|
answers._can_pair = true;
|
||||||
}
|
}
|
||||||
|
answers.relay = relay;
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,17 +40,18 @@ common.parseUrl = function (hostname) {
|
||||||
|
|
||||||
common.apiDirectory = '_apis/telebit.cloud/index.json';
|
common.apiDirectory = '_apis/telebit.cloud/index.json';
|
||||||
common.urequest = function (opts, cb) {
|
common.urequest = function (opts, cb) {
|
||||||
|
var https = require('https');
|
||||||
// request.js behavior:
|
// request.js behavior:
|
||||||
// encoding: null + json ? unknown
|
// encoding: null + json ? unknown
|
||||||
// json => attempt to parse, fail silently
|
// json => attempt to parse, fail silently
|
||||||
// encoding => buffer.toString(encoding)
|
// encoding => buffer.toString(encoding)
|
||||||
// null === encoding => Buffer.concat(buffers)
|
// null === encoding => Buffer.concat(buffers)
|
||||||
https.get(opts, function (resp) {
|
https.get(opts.url, function (resp) {
|
||||||
var encoding = opts.encoding;
|
var encoding = opts.encoding;
|
||||||
if (null === encoding) {
|
if (null === encoding) {
|
||||||
resp._body = [];
|
resp._body = [];
|
||||||
} else {
|
} else {
|
||||||
resp._body = '';
|
resp.body = '';
|
||||||
}
|
}
|
||||||
if (!resp.headers['content-length'] || 0 === parseInt(resp.headers['content-length'], 10)) {
|
if (!resp.headers['content-length'] || 0 === parseInt(resp.headers['content-length'], 10)) {
|
||||||
cb(resp);
|
cb(resp);
|
||||||
|
|
Loading…
Reference in New Issue