From 2d6814cf79bf6f509e527901179f09b9fb23efaf Mon Sep 17 00:00:00 2001 From: weightedangelcube Date: Sun, 2 Mar 2025 16:32:17 -0700 Subject: [PATCH] fix: proxy cors url query --- src/scripts/index.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/scripts/index.ts b/src/scripts/index.ts index f22d6a8..393b95a 100644 --- a/src/scripts/index.ts +++ b/src/scripts/index.ts @@ -1,18 +1,16 @@ - - async function fetchCarbon() : Promise { - const url : string = "https://corsproxy.io/?https://api.websitecarbon.com/site?url=" + window.location.hostname; - const response : Response = await fetch(url, { - method: "GET" - }); + const url : string = "https://corsproxy.io/?url=https://api.websitecarbon.com/site?url=" + window.location.hostname; + + const response : Response = await fetch(url); + console.log(response); return await response.json().then(data => data.statistics.co2.grid.litres); } window.onload = async function() { try { document.getElementById('carbon').innerHTML = "your visit to this website produced " + Math.round(await fetchCarbon() * 1000) + " mL of carbon dioxide!"; - } catch { + } catch (error) { document.getElementById('carbon').innerHTML = "unable to load carbon usage!"; + console.log(error); } - }; \ No newline at end of file -- 2.51.2