Skip to content

Commit

Permalink
fix: don't crash inside cloudflare workers
Browse files Browse the repository at this point in the history
  • Loading branch information
threepointone committed Dec 5, 2023
1 parent 6ad41e1 commit 501663a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libs/client/src/request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { getConfig } from './config';
import { getUserAgent, isBrowser } from './runtime';

const isCloudflareWorkers =
typeof navigator !== 'undefined' &&
navigator?.userAgent === 'Cloudflare-Workers';

export async function dispatchRequest<Input, Output>(
method: string,
targetUrl: string,
Expand Down Expand Up @@ -37,7 +41,7 @@ export async function dispatchRequest<Input, Output>(
const response = await fetch(url, {
method,
headers: requestHeaders,
mode: 'cors',
...(!isCloudflareWorkers && { mode: 'cors' }),
body:
method.toLowerCase() !== 'get' && input
? JSON.stringify(input)
Expand Down

0 comments on commit 501663a

Please sign in to comment.