Skip to content

Commit

Permalink
fix: omit some fetch options when running in Cloudflare Workers env
Browse files Browse the repository at this point in the history
closes #255
  • Loading branch information
panva committed Sep 2, 2021
1 parent c0bc79e commit ced065a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Legend:
| -- | -- | -- |
| Node.js | LTS ^12.19.0 || ^14.15.0 | |
| Electron | ^12.0.0 | see <sup>[1]</sup> |
| Cloudflare Workers || see <sup>[2], [4]</sup> |
| Deno | experimental | see Deno's [Web Cryptography API roadmap](https://github.com/denoland/deno/issues/11690) |
| React Native || has no available and usable crypto runtime |
| IE || implements old version of the Web Cryptography API specification |
Expand Down
13 changes: 10 additions & 3 deletions src/runtime/browser/fetch_jwks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ const fetchJwks: FetchFunction = async (url: URL, timeout: number) => {
const response = await globalThis.fetch(url.href, {
signal: controller ? controller.signal : undefined,
redirect: 'manual',
referrerPolicy: 'no-referrer',
credentials: 'omit',
mode: 'cors',
method: 'GET',
// do not pass referrerPolicy, credentials, and mode when running
// in Cloudflare Workers environment
// @ts-expect-error
...(typeof globalThis.WebSocketPair === 'undefined'
? {
referrerPolicy: 'no-referrer',
credentials: 'omit',
mode: 'cors',
}
: undefined),
})

if (response.status !== 200) {
Expand Down

0 comments on commit ced065a

Please sign in to comment.