Skip to content

Commit

Permalink
chore(web): cors fetch to pobb.in
Browse files Browse the repository at this point in the history
  • Loading branch information
atty303 committed May 26, 2024
1 parent 16c5cc4 commit 386b356
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions packages/web/src/PobWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,37 @@ export default function PobWindow(props: {
},
onFrame,
onFetch: async (url, headers, body) => {
const rep = await fetch("/api/fetch", {
method: "POST",
body: JSON.stringify({ url, headers, body }),
});
return await rep.json();
let rep = undefined;

if (url.startsWith("https://pobb.in/")) {
try {
const r = await fetch(url, {
method: body ? "POST" : "GET",
body,
headers,
});
if (r.ok) {
rep = {
body: await r.text(),
headers: Object.fromEntries(r.headers.entries()),
status: r.status,
};
log.debug(tag.pob, "CORS fetch success", url, rep);
}
} catch (e) {
log.warn(tag.pob, "CORS fetch error", e);
}
}

if (!rep) {
const r = await fetch("/api/fetch", {
method: "POST",
body: JSON.stringify({ url, headers, body }),
});
rep = await r.json();
}

return rep;
},
onTitleChange,
});
Expand Down

0 comments on commit 386b356

Please sign in to comment.