Skip to content

Commit 787b673

Browse files
authored
Merge pull request #96 from TrianguloY/notCorsFirst
Try fetching without proxy first
2 parents 3545688 + dfb47f7 commit 787b673

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Diff for: htmlpreview.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989

9090
var fetchProxy = function (url, options, i) {
9191
var proxy = [
92+
'', // try without proxy first
9293
'https://api.codetabs.com/v1/proxy/?quest='
9394
];
9495
return fetch(proxy[i] + url, options).then(function (res) {
@@ -102,10 +103,7 @@
102103
};
103104

104105
if (url && url.indexOf(location.hostname) < 0)
105-
fetch(url).then(function (res) {
106-
if (!res.ok) throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText);
107-
return res.text();
108-
}).then(loadHTML).catch(function (error) {
106+
fetchProxy(url, null, 0).then(loadHTML).catch(function (error) {
109107
console.error(error);
110108
previewForm.style.display = 'block';
111109
previewForm.innerText = error;

0 commit comments

Comments
 (0)