Merge pull request #33 from threepointone/main

fix: don't crash inside cloudflare workers
This commit is contained in:
gorkem 2023-12-08 16:08:07 -08:00 committed by GitHub
commit 6f95c6561b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,
@ -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)