Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
fix paths in patch
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Sep 23, 2024
1 parent 780ed51 commit 8a42727
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,31 @@ function patchModuleFallbackHandler(
handler: ModuleFallbackHandler,
): ModuleFallbackHandler {
return async request => {
const response = await handler(request);
const url = new URL(request.url);

for (const pathName of ['referrer', 'specifier']) {
const path = url.searchParams.get(pathName);
if (path) {
// workerd always adds a `/` to the absolute paths (raw values excluded) that is fine in OSes like mac and linux
// where absolute paths do start with `/` as well. But it is not ok in windows where absolute paths don't start
// with `/`, so for windows we need to remove the extra leading `/`
//
// Either way this is an issue caused by workerd adding the leading `/`, if it were not to do that and simply return
// the correct path the path would not need fixing
//
const fixedPath =
process.platform !== 'win32' ? path : path.replace(/^\//, '');
url.searchParams.set(pathName, fixedPath);
}
}

const { referrerPolicy, ...reqRest } = request;
const fixedRequest = new Request(url, {
...reqRest,
});

const response = await handler(fixedRequest);

if (response.status === 200) {
const respJson = (await response.json()) as Record<string, string>;
return Response.json({
Expand Down

0 comments on commit 8a42727

Please sign in to comment.