improve loki tld host checking, fix proxyFetch calling sendToProxy so tokens can be fetched

pull/1037/head
Ryan Tharp 5 years ago
parent 3e86acb2e5
commit 4c870d4b74

@ -269,7 +269,7 @@ const serverRequest = async (endpoint, options = {}) => {
)); ));
} else { } else {
// disable check for .loki // disable check for .loki
process.env.NODE_TLS_REJECT_UNAUTHORIZED = url.host.match(/\.loki$/i) process.env.NODE_TLS_REJECT_UNAUTHORIZED = host.match(/\.loki$/i)
? '0' ? '0'
: '1'; : '1';
result = await nodeFetch(url, fetchOptions); result = await nodeFetch(url, fetchOptions);
@ -298,7 +298,7 @@ const serverRequest = async (endpoint, options = {}) => {
url url
); );
} }
if (mode === '_sendToProxy') { if (mode === 'sendToProxy') {
// if we can detect, certain types of failures, we can retry... // if we can detect, certain types of failures, we can retry...
if (e.code === 'ECONNRESET') { if (e.code === 'ECONNRESET') {
// retry with counter? // retry with counter?
@ -658,7 +658,7 @@ class LokiAppDotNetServerAPI {
try { try {
const res = await this.proxyFetch( const res = await this.proxyFetch(
`${this.baseServerUrl}/loki/v1/submit_challenge`, new URL(`${this.baseServerUrl}/loki/v1/submit_challenge`),
fetchOptions, fetchOptions,
{ textResponse: true } { textResponse: true }
); );
@ -683,7 +683,8 @@ class LokiAppDotNetServerAPI {
} }
const urlStr = urlObj.toString(); const urlStr = urlObj.toString();
const endpoint = urlStr.replace(`${this.baseServerUrl}/`, ''); const endpoint = urlStr.replace(`${this.baseServerUrl}/`, '');
const { response, result } = await this._sendToProxy( const { response, result } = await sendToProxy(
this.pubKey,
endpoint, endpoint,
finalOptions, finalOptions,
options options
@ -694,8 +695,8 @@ class LokiAppDotNetServerAPI {
json: () => response, json: () => response,
}; };
} }
const urlStr = urlObj.toString(); const host = urlObj.host.toLowerCase();
if (urlStr.match(/\.loki\//)) { if (host.match(/\.loki$/)) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
} }
const result = nodeFetch(urlObj, fetchOptions, options); const result = nodeFetch(urlObj, fetchOptions, options);

Loading…
Cancel
Save