Merge pull request #33 from threepointone/main
fix: don't crash inside cloudflare workers
This commit is contained in:
commit
6f95c6561b
@ -1,6 +1,10 @@
|
|||||||
import { getConfig } from './config';
|
import { getConfig } from './config';
|
||||||
import { getUserAgent, isBrowser } from './runtime';
|
import { getUserAgent, isBrowser } from './runtime';
|
||||||
|
|
||||||
|
const isCloudflareWorkers =
|
||||||
|
typeof navigator !== 'undefined' &&
|
||||||
|
navigator?.userAgent === 'Cloudflare-Workers';
|
||||||
|
|
||||||
export async function dispatchRequest<Input, Output>(
|
export async function dispatchRequest<Input, Output>(
|
||||||
method: string,
|
method: string,
|
||||||
targetUrl: string,
|
targetUrl: string,
|
||||||
@ -37,7 +41,7 @@ export async function dispatchRequest<Input, Output>(
|
|||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method,
|
method,
|
||||||
headers: requestHeaders,
|
headers: requestHeaders,
|
||||||
mode: 'cors',
|
...(!isCloudflareWorkers && { mode: 'cors' }),
|
||||||
body:
|
body:
|
||||||
method.toLowerCase() !== 'get' && input
|
method.toLowerCase() !== 'get' && input
|
||||||
? JSON.stringify(input)
|
? JSON.stringify(input)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user