1import { fetch } from "https://esm.town/v/std/fetch";
2
3const gist =
5
6export const queryParams = async (req: Request) => {
7 const data = await fetch(gist);
8 const jsonData = await data.json();
9
1// make POST fetch to https://stevekrouse-parsePostBodyExample.web.val.run
2console.log(
3 await (await fetch("https://stevekrouse-parsePostBodyExample.web.val.run", {
4 method: "POST",
5 headers: {
1import { dataToRSS } from "https://esm.town/v/Glench/dataToRSS";
2import { fetch } from "https://esm.town/v/std/fetch";
3
4async function getOfficialRedditPosts() {
5 const resp = await fetch("https://www.reddit.com/r/googlephotos/.json");
6 if (!resp.ok) return [];
7 const json = await resp.json();
13}
14async function getGoogleSupportForumPosts() {
15 const resp = await fetch(
16 "https://support.google.com/photos/threads?hl=en&max_results=500",
17 );
4
5const root = createRoot(document.getElementById("app"));
6let initialTodos = await fetch("https://stevekrouse-todo_list.web.val.run/todos").then(r => r.json());
7root.render(_jsx(TodoApp, { initialTodos: initialTodos }));
5It doesn't do as much as other transpilers (such as esm.sh, such as rewriting `npm:` imports, etc). We may add that capability in the future. For now, if you want your npm imports to run in the browser, use `https://esm.sh/package` instead of `npm:package`.
6
7The below script demonstrates this transiplation behavior by fetching its own source code (`import.meta.url`) with the user agent of a browser. You can uncoment the line setting the browser agent if you want to see the difference in the output. Or you could just load this val's module URL in your browser to see the untranspiled TS.
8
9As of July 23, 2024, this is the code that determines when esm.town transpiles or not:
90});
91
92export default app.fetch;
3
4/**
5 * @param handler Fetch handler
6 */
7export default function openInValTown(
1import { email } from "https://esm.town/v/std/email";
2import { fetch } from "https://esm.town/v/std/fetch";
3
4export const isMyWebsiteDown = async () => {
8 let reason: string;
9 try {
10 const res = await fetch(URL);
11 if (res.status !== 200) {
12 reason = `(status code: ${res.status})`;
14 }
15 } catch (e) {
16 reason = `couldn't fetch: ${e}`;
17 ok = false;
18 }
3
4export async function flydotioRSS(req: Request): Promise<Response> {
5 const response = await fetch("https://fly.io/blog/");
6 const body = await response.text();
7 const $ = cheerio.load(body);
8}
9
10export default app.fetch;
11