Skip to content

Commit 6582ede

Browse files
committed
Add support for Cloudflare Workers (ethers-io#1886).
1 parent f3c6d81 commit 6582ede

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

packages/web/src.ts/browser-geturl.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ export { GetUrlResponse, Options };
99
export async function getUrl(href: string, options?: Options): Promise<GetUrlResponse> {
1010
if (options == null) { options = { }; }
1111

12-
const request = {
12+
const request: RequestInit = {
1313
method: (options.method || "GET"),
1414
headers: (options.headers || { }),
1515
body: (options.body || undefined),
16+
};
1617

17-
mode: <RequestMode>"cors", // no-cors, cors, *same-origin
18-
cache: <RequestCache>"no-cache", // *default, no-cache, reload, force-cache, only-if-cached
19-
credentials: <RequestCredentials>"same-origin", // include, *same-origin, omit
20-
redirect: <RequestRedirect>"follow", // manual, *follow, error
21-
referrer: "client", // no-referrer, *client
18+
if (options.skipFetchSetup !== true) {
19+
request.mode = <RequestMode>"cors"; // no-cors, cors, *same-origin
20+
request.cache = <RequestCache>"no-cache"; // *default, no-cache, reload, force-cache, only-if-cached
21+
request.credentials = <RequestCredentials>"same-origin"; // include, *same-origin, omit
22+
request.redirect = <RequestRedirect>"follow"; // manual, *follow, error
23+
request.referrer = "client"; // no-referrer, *client
2224
};
2325

2426
const response = await fetch(href, request);

packages/web/src.ts/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
"use strict";
22

33
export type GetUrlResponse = {
4-
statusCode: number,
4+
statusCode: number;
55
statusMessage: string;
66
headers: { [ key: string] : string };
77
body: Uint8Array;
88
};
99

1010
export type Options = {
11-
method?: string,
11+
method?: string;
1212
allowGzip?: boolean;
13-
body?: Uint8Array
14-
headers?: { [ key: string] : string },
13+
body?: Uint8Array;
14+
headers?: { [ key: string] : string };
15+
skipFetchSetup?: boolean;
1516
};
1617

0 commit comments

Comments
 (0)