Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

fix(deploy): Don't try to mutate fetch response's headers #190

Merged
merged 1 commit into from
Apr 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions deploy/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ serve({
return notFound();
}
const isBrowser = request.headers.get("accept")?.includes("text/html");
// The headers on a `Response` are immutable
const headers = new Headers(resp.headers);
// Responses as plain text to browsers
resp.headers.set(
headers.set(
"content-type",
isBrowser ? "text/plain" : "application/typescript; charset=utf-8",
);
// Prevents downloading the file
resp.headers.delete("content-disposition");
return resp;
headers.delete("content-disposition");
return new Response(resp.body, { ...resp, headers });
},
404: () => notFound(),
});
Expand Down