Readme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { API_URL } from "https://esm.town/v/std/API_URL";
/**
* Wraps the JavaScript Fetch function to anonymize where the request is
* coming from ([Docs ↗](https://docs.val.town/std/fetch))
*
* @param {string | URL | Request} input - The resource 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 | Request, requestInit?: RequestInit) {
const origReq = new Request(input, requestInit);
const url = new URL("/v1/fetch", API_URL);
url.searchParams.set("url", origReq.url);
const req = new Request(url, origReq);
req.headers.set("X-Valtown-Authorization", `Bearer ${Deno.env.get("valtown")}`);
return globalThis.fetch(req);
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.
Comments
stevekrouse avatar

The main comment is probably too long. Maybe we can link out to the full docs from the JSDdoc widget? That could be neat.

Also, include the params in the JSDoc string?

andreterron avatar

With params:

image.png

And we don't need to specify RequestInit's fields, since it has its own JSDocs:

image.png

stevekrouse avatar

I tweaked it a bit

/**
 * Wraps the JavaScript Fetch function to anonymize where the request is coming from ([Docs ↗](https://docs.val.town/std/fetch))
 *
 * @param {string | URL} url - The URL to fetch
 * @param {RequestInit} [requestInit] - Optional configuration data (HTTP method, headers, etc) ([Docs ↗](https://deno.land/api@v1.42.1?s=RequestInit))
 */

I think we should also consider adding the type (ie string or RequestInit) in such a way that it shows up on hover or changing the product to render that info.