From 61cbb9e6dae9c466dd82d7deb7108e7d73b3674c Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 8 Jul 2024 14:37:12 +0200 Subject: [PATCH] js: Apply workaround for incomplete fetch support in Cloudflare Worker --- javascript/src/openapi/http/isomorphic-fetch.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/javascript/src/openapi/http/isomorphic-fetch.ts b/javascript/src/openapi/http/isomorphic-fetch.ts index 1ad779f30..f62d4f388 100644 --- a/javascript/src/openapi/http/isomorphic-fetch.ts +++ b/javascript/src/openapi/http/isomorphic-fetch.ts @@ -32,11 +32,16 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary { let method = request.getHttpMethod().toString(); let body = request.getBody(); + // Cloudflare Workers fail if the credentials option is used in a fetch call. + // This work around that. Source: + // https://github.com/cloudflare/workers-sdk/issues/2514#issuecomment-2178070014 + const isCredentialsSupported = "credentials" in Request.prototype; + return fetch(request.getUrl(), { method: method, body: body as any, headers: request.getHeaders(), - credentials: "same-origin" + credentials: isCredentialsSupported ? "same-origin" : undefined }).then((resp: any) => { const headers: { [name: string]: string } = {}; resp.headers.forEach((value: string, name: string) => {