From cc8215addcb9a7d263410c8fd926a0987b571a75 Mon Sep 17 00:00:00 2001 From: Jakob Heuser Date: Mon, 25 Nov 2024 21:11:08 -0800 Subject: [PATCH] fix: Fixes bypass logic for remote Wasm --- .changeset/funny-coins-bow.md | 5 +++++ src/lib/handler.ts | 8 ++++++-- src/lib/taskless.ts | 14 +++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .changeset/funny-coins-bow.md diff --git a/.changeset/funny-coins-bow.md b/.changeset/funny-coins-bow.md new file mode 100644 index 0000000..89575d5 --- /dev/null +++ b/.changeset/funny-coins-bow.md @@ -0,0 +1,5 @@ +--- +"@taskless/loader": patch +--- + +Fixes the bypass logic for remote Wasm modules diff --git a/src/lib/handler.ts b/src/lib/handler.ts index e8f1510..58590ad 100644 --- a/src/lib/handler.ts +++ b/src/lib/handler.ts @@ -31,12 +31,16 @@ export const createHandler = ({ getModules: () => Promise>>; }) => 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; } diff --git a/src/lib/taskless.ts b/src/lib/taskless.ts index 2683982..327f251 100644 --- a/src/lib/taskless.ts +++ b/src/lib/taskless.ts @@ -215,6 +215,10 @@ export const taskless = ( params: { version: "v1", }, + headers: { + authorization: `Bearer ${secret}`, + ...bypass, + }, }); } catch {} } @@ -257,6 +261,7 @@ export const taskless = ( headers: { authorization: `Bearer ${secret}`, "Content-Type": "application/json", + ...bypass, }, body: JSON.stringify(networkPayload), }, @@ -318,6 +323,7 @@ export const taskless = ( const response = await client["/{version}/config"].get({ headers: { authorization: `Bearer ${secret}`, + ...bypass, }, params: { version: "pre1", @@ -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(); })() );