Skip to content

Commit

Permalink
fix: use Response.redirect for redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
SegaraRai committed Dec 4, 2023
1 parent 1dce0a5 commit 0cf89bc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions swEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,17 @@ async function handleEvent(url: URL, event: FetchEvent): Promise<Response> {

event.waitUntil(storeCookiesFromResponse(res.headers));

const resFixed = new Response(res.body, res);
resFixed.headers.delete("set-cookie");
const locationHeader = resFixed.headers.get("location");
const locationHeader = res.headers.get("location");
if (locationHeader) {
resFixed.headers.set(
"location",
new URL(locationHeader, url.origin).toString()
return Response.redirect(
new URL(locationHeader, url.origin).toString(),
res.status
);
}

const resFixed = new Response(res.body, res);
resFixed.headers.delete("set-cookie");

return resFixed;
}

Expand Down

0 comments on commit 0cf89bc

Please sign in to comment.