Skip to content

Commit

Permalink
fix: workaround itty-router issue with cached responses
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Dec 19, 2024
1 parent db220f1 commit 62e4ec6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion functions/explorers/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ const router = Router<
[URL, Env, Etag, EventContext<unknown, any, Record<string, unknown>>]
>({
before: [preflight],
finally: [corsify],
finally: [
// This is a workaround for a bug in itty-router; without this, we would get 500 errors with
// "Can't modify immutable headers." for requests served from cache.
// see https://github.com/kwhitley/itty-router/issues/242#issuecomment-2194227007
(resp: Response) => corsify(new Response(resp.body, resp)),
],
})
router
.get(
Expand Down
7 changes: 6 additions & 1 deletion functions/grapher/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ const router = Router<
[URL, Env, Etag, EventContext<unknown, any, Record<string, unknown>>]
>({
before: [preflight],
finally: [corsify],
finally: [
// This is a workaround for a bug in itty-router; without this, we would get 500 errors with
// "Can't modify immutable headers." for requests served from cache.
// see https://github.com/kwhitley/itty-router/issues/242#issuecomment-2194227007
(resp: Response) => corsify(new Response(resp.body, resp)),
],
})
router
.get(
Expand Down
7 changes: 6 additions & 1 deletion functions/grapher/by-uuid/[uuid].ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ const { preflight, corsify } = cors({

const router = Router<IRequestStrict, [URL, Env, string]>({
before: [preflight],
finally: [corsify],
finally: [
// This is a workaround for a bug in itty-router; without this, we would get 500 errors with
// "Can't modify immutable headers." for requests served from cache.
// see https://github.com/kwhitley/itty-router/issues/242#issuecomment-2194227007
(resp: Response) => corsify(new Response(resp.body, resp)),
],
})

router
Expand Down

0 comments on commit 62e4ec6

Please sign in to comment.