1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { API_URL } from "https://esm.town/v/std/API_URL";
import { rawFetch } from "https://esm.town/v/std/rawFetch";
/**
* Wraps the JavaScript Fetch function to anonymize where the request is
* coming from ([Docs β†—](https://docs.val.town/std/fetch))
*
* @param {string | URL} input - The URL to fetch
* @param {RequestInit} [requestInit] - Optional configuration data (HTTP
* method, headers, etc) ([Docs β†—](https://deno.land/api@v1.42.1?s=RequestInit))
*/
export async function fetch(input: string | URL, requestInit?: RequestInit) {
let query = new URLSearchParams({
url: input.toString(),
});
return rawFetch(`${API_URL}/v1/fetch?${query}`, {
...requestInit,
headers: {
"X-Valtown-Authorization": `Bearer ${Deno.env.get("valtown")}`,
...requestInit?.headers ?? {},
},
});
}