Skip to content

Commit

Permalink
use new cors proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Aug 4, 2023
1 parent 9cdeacf commit 23ba42d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,14 @@

async function runAllDeployments() {

const CorsProxy = "https://cors.bridged.cc/"
function corsProxify(url) {
return `https://slorber-cors-proxy.vercel.app/api?url=${encodeURIComponent(url)}`
}

async function fetchDeploymentUrl(deployment,url) {
const absoluteUrl = `${deployment.url}${url}`;
const corsProxyUrl = `${CorsProxy}${absoluteUrl}`;
const response = await fetch(corsProxyUrl);
const corsProxyUrl = corsProxify(absoluteUrl);
const response = await fetch(corsProxyUrl,{redirect: "manual"});

// Mostly for GH pages
function removeDeploymentBaseUrl(str) {
Expand All @@ -215,9 +217,10 @@
return str.replace(baseUrl,"");
}

// cors proxy impl details :'(
const finalUrl = response.headers.get("x-final-url");
const redirectUrl = absoluteUrl !== finalUrl ? removeDeploymentBaseUrl(new URL(finalUrl).pathname) : undefined;
const finalUrl = response.headers.get("Location") ?? url;

// console.log({url, finalUrl});
const redirectUrl = absoluteUrl !== finalUrl ? removeDeploymentBaseUrl(new URL(finalUrl,"https://example.com").pathname) : undefined;

return {
url,
Expand Down

0 comments on commit 23ba42d

Please sign in to comment.