Skip to content

Commit

Permalink
Add support for Cloudflare Workers (#1886).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Oct 5, 2021
1 parent f3c6d81 commit 6582ede
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 8 additions & 6 deletions packages/web/src.ts/browser-geturl.ts
Expand Up @@ -9,16 +9,18 @@ export { GetUrlResponse, Options };
export async function getUrl(href: string, options?: Options): Promise<GetUrlResponse> {
if (options == null) { options = { }; }

const request = {
const request: RequestInit = {
method: (options.method || "GET"),
headers: (options.headers || { }),
body: (options.body || undefined),
};

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

const response = await fetch(href, request);
Expand Down
9 changes: 5 additions & 4 deletions packages/web/src.ts/types.ts
@@ -1,16 +1,17 @@
"use strict";

export type GetUrlResponse = {
statusCode: number,
statusCode: number;
statusMessage: string;
headers: { [ key: string] : string };
body: Uint8Array;
};

export type Options = {
method?: string,
method?: string;
allowGzip?: boolean;
body?: Uint8Array
headers?: { [ key: string] : string },
body?: Uint8Array;
headers?: { [ key: string] : string };
skipFetchSetup?: boolean;
};

0 comments on commit 6582ede

Please sign in to comment.