From c643d436dbe09f5616b3bdd01773f81d8cad1da5 Mon Sep 17 00:00:00 2001 From: j4k0xb <55899582+j4k0xb@users.noreply.github.com> Date: Sun, 8 Dec 2024 17:37:40 +0100 Subject: [PATCH] fix: use cors proxy when fetching fails --- apps/playground/src/App.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/playground/src/App.tsx b/apps/playground/src/App.tsx index 39efdbcd..3b11102b 100644 --- a/apps/playground/src/App.tsx +++ b/apps/playground/src/App.tsx @@ -184,9 +184,12 @@ function App() { } async function loadFromURL(url: string) { - const response = await fetch(url).catch(() => - fetch('https://corsproxy.io/?' + encodeURIComponent(url)), - ); + let response = await fetch(url); + if (!response.ok) { + response = await fetch( + 'https://corsproxy.io/?' + encodeURIComponent(url), + ); + } if (response.ok) { const model = activeTab() || openUntitledTab(); model.setValue(await response.text());