From 501663a311ed856aa26393da4b9260d32f2a0f21 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Tue, 5 Dec 2023 11:43:47 +0000 Subject: [PATCH] fix: don't crash inside cloudflare workers --- libs/client/src/request.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/client/src/request.ts b/libs/client/src/request.ts index bf86683..19af2a2 100644 --- a/libs/client/src/request.ts +++ b/libs/client/src/request.ts @@ -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( method: string, targetUrl: string, @@ -37,7 +41,7 @@ export async function dispatchRequest( const response = await fetch(url, { method, headers: requestHeaders, - mode: 'cors', + ...(!isCloudflareWorkers && { mode: 'cors' }), body: method.toLowerCase() !== 'get' && input ? JSON.stringify(input)