Add support for Cloudflare Workers (#1886).
This commit is contained in:
parent
f3c6d819f3
commit
6582ede1ce
@ -9,16 +9,18 @@ export { GetUrlResponse, Options };
|
|||||||
export async function getUrl(href: string, options?: Options): Promise<GetUrlResponse> {
|
export async function getUrl(href: string, options?: Options): Promise<GetUrlResponse> {
|
||||||
if (options == null) { options = { }; }
|
if (options == null) { options = { }; }
|
||||||
|
|
||||||
const request = {
|
const request: RequestInit = {
|
||||||
method: (options.method || "GET"),
|
method: (options.method || "GET"),
|
||||||
headers: (options.headers || { }),
|
headers: (options.headers || { }),
|
||||||
body: (options.body || undefined),
|
body: (options.body || undefined),
|
||||||
|
};
|
||||||
|
|
||||||
mode: <RequestMode>"cors", // no-cors, cors, *same-origin
|
if (options.skipFetchSetup !== true) {
|
||||||
cache: <RequestCache>"no-cache", // *default, no-cache, reload, force-cache, only-if-cached
|
request.mode = <RequestMode>"cors"; // no-cors, cors, *same-origin
|
||||||
credentials: <RequestCredentials>"same-origin", // include, *same-origin, omit
|
request.cache = <RequestCache>"no-cache"; // *default, no-cache, reload, force-cache, only-if-cached
|
||||||
redirect: <RequestRedirect>"follow", // manual, *follow, error
|
request.credentials = <RequestCredentials>"same-origin"; // include, *same-origin, omit
|
||||||
referrer: "client", // no-referrer, *client
|
request.redirect = <RequestRedirect>"follow"; // manual, *follow, error
|
||||||
|
request.referrer = "client"; // no-referrer, *client
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch(href, request);
|
const response = await fetch(href, request);
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
export type GetUrlResponse = {
|
export type GetUrlResponse = {
|
||||||
statusCode: number,
|
statusCode: number;
|
||||||
statusMessage: string;
|
statusMessage: string;
|
||||||
headers: { [ key: string] : string };
|
headers: { [ key: string] : string };
|
||||||
body: Uint8Array;
|
body: Uint8Array;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Options = {
|
export type Options = {
|
||||||
method?: string,
|
method?: string;
|
||||||
allowGzip?: boolean;
|
allowGzip?: boolean;
|
||||||
body?: Uint8Array
|
body?: Uint8Array;
|
||||||
headers?: { [ key: string] : string },
|
headers?: { [ key: string] : string };
|
||||||
|
skipFetchSetup?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user