From 1e4aa6dbb4a48362dea5c1537bbeed9a95d15c7d Mon Sep 17 00:00:00 2001 From: TrianguloY Date: Fri, 16 Oct 2020 12:32:00 +0200 Subject: [PATCH 1/3] Try fetching without proxy first When fetching a resource, try directly first. If it throws an error, then try with proxies. Fixes #95 Should also reduce drastically the petitions to the proxy servers (will only be made if the non-proxy fails) --- htmlpreview.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/htmlpreview.js b/htmlpreview.js index 2f08b15..d3996eb 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -89,6 +89,7 @@ var fetchProxy = function (url, options, i) { var proxy = [ + '', // try without proxy first 'https://cors-anywhere.herokuapp.com/', 'https://yacdn.org/proxy/', 'https://api.codetabs.com/v1/proxy/?quest=' @@ -104,10 +105,7 @@ }; if (url && url.indexOf(location.hostname) < 0) - fetch(url).then(function (res) { - if (!res.ok) throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText); - return res.text(); - }).then(loadHTML).catch(function (error) { + fetchProxy(url, null, 0).then(loadHTML).catch(function (error) { console.error(error); previewForm.style.display = 'block'; previewForm.innerText = error; From a60683d86024c899d0b8165861d15cd1c8f65198 Mon Sep 17 00:00:00 2001 From: Peter Chubb Date: Fri, 9 Jul 2021 14:23:16 +1000 Subject: [PATCH 2/3] Delete no-longer-running yacdn.org proxy. yacdn.org has been down for some time. Having it in the list of proxies means that attempting to view generated HTML can take a long time, before connection attempts time out. --- htmlpreview.js | 1 - 1 file changed, 1 deletion(-) diff --git a/htmlpreview.js b/htmlpreview.js index 2f08b15..57b9009 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -90,7 +90,6 @@ var fetchProxy = function (url, options, i) { var proxy = [ 'https://cors-anywhere.herokuapp.com/', - 'https://yacdn.org/proxy/', 'https://api.codetabs.com/v1/proxy/?quest=' ]; return fetch(proxy[i] + url, options).then(function (res) { From 6a635bd194dda9abf1c573f623d241ebe45af689 Mon Sep 17 00:00:00 2001 From: Peter Chubb Date: Fri, 9 Jul 2021 14:32:23 +1000 Subject: [PATCH 3/3] 'https://cors-anywhere.herokuapp.com/' is also broken See https://github.com/Rob--W/cors-anywhere/issues/301 Signed-off-by: Peter Chubb --- htmlpreview.js | 1 - 1 file changed, 1 deletion(-) diff --git a/htmlpreview.js b/htmlpreview.js index 57b9009..f5e1eb7 100644 --- a/htmlpreview.js +++ b/htmlpreview.js @@ -89,7 +89,6 @@ var fetchProxy = function (url, options, i) { var proxy = [ - 'https://cors-anywhere.herokuapp.com/', 'https://api.codetabs.com/v1/proxy/?quest=' ]; return fetch(proxy[i] + url, options).then(function (res) {