Skip to content

Commit

Permalink
Merge pull request #96 from TrianguloY/notCorsFirst
Browse files Browse the repository at this point in the history
Try fetching without proxy first
  • Loading branch information
niutech authored Jul 11, 2021
2 parents 3545688 + dfb47f7 commit 787b673
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions htmlpreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@

var fetchProxy = function (url, options, i) {
var proxy = [
'', // try without proxy first
'https://api.codetabs.com/v1/proxy/?quest='
];
return fetch(proxy[i] + url, options).then(function (res) {
Expand All @@ -102,10 +103,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;
Expand Down

0 comments on commit 787b673

Please sign in to comment.