Skip to content

Commit 61cbb9e

Browse files
committed
js: Apply workaround for incomplete fetch support in Cloudflare Worker
1 parent b9e63ea commit 61cbb9e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

javascript/src/openapi/http/isomorphic-fetch.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
3232
let method = request.getHttpMethod().toString();
3333
let body = request.getBody();
3434

35+
// Cloudflare Workers fail if the credentials option is used in a fetch call.
36+
// This work around that. Source:
37+
// https://github.com/cloudflare/workers-sdk/issues/2514#issuecomment-2178070014
38+
const isCredentialsSupported = "credentials" in Request.prototype;
39+
3540
return fetch(request.getUrl(), {
3641
method: method,
3742
body: body as any,
3843
headers: request.getHeaders(),
39-
credentials: "same-origin"
44+
credentials: isCredentialsSupported ? "same-origin" : undefined
4045
}).then((resp: any) => {
4146
const headers: { [name: string]: string } = {};
4247
resp.headers.forEach((value: string, name: string) => {

0 commit comments

Comments
 (0)