Skip to content

Commit

Permalink
js: Apply workaround for incomplete fetch support in Cloudflare Worker
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Jul 8, 2024
1 parent b9e63ea commit 61cbb9e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion javascript/src/openapi/http/isomorphic-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 61cbb9e

Please sign in to comment.