Skip to content

Commit

Permalink
fix: Fixes bypass logic for remote Wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobo committed Nov 26, 2024
1 parent 526d73a commit cc8215a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-coins-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@taskless/loader": patch
---

Fixes the bypass logic for remote Wasm modules
8 changes: 6 additions & 2 deletions src/lib/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ export const createHandler = ({
getModules: () => Promise<Map<string, Promise<Plugin>>>;
}) =>
http.all("https://*", async (info) => {
// let a bypassed request through to any other handlers
if (isBypassed(info.request)) {
return undefined;
}

// wait for loaded to unblock (means the shim library has loaded)
// !ok means disable the library's functionality
const ok = await loaded;

// let a bypassed request through to any other handlers
if (!ok || isBypassed(info.request)) {
if (!ok) {
return undefined;
}

Expand Down
14 changes: 13 additions & 1 deletion src/lib/taskless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ export const taskless = (
params: {
version: "v1",
},
headers: {
authorization: `Bearer ${secret}`,
...bypass,
},
});
} catch {}
}
Expand Down Expand Up @@ -257,6 +261,7 @@ export const taskless = (
headers: {
authorization: `Bearer ${secret}`,
"Content-Type": "application/json",
...bypass,
},
body: JSON.stringify(networkPayload),
},
Expand Down Expand Up @@ -318,6 +323,7 @@ export const taskless = (
const response = await client["/{version}/config"].get({
headers: {
authorization: `Bearer ${secret}`,
...bypass,
},
params: {
version: "pre1",
Expand Down Expand Up @@ -368,7 +374,13 @@ export const taskless = (
moduleSource.set(
ident,
(async () => {
const data = await fetch(pack.url.source);
logger.trace(`Fetching ${ident} from ${pack.url.source}`);
const data = await fetch(pack.url.source, {
headers: {
...bypass,
},
});
logger.trace(`Fetched ${ident} from ${pack.url.source}`);
return data.arrayBuffer();
})()
);
Expand Down

0 comments on commit cc8215a

Please sign in to comment.