37
38/**
39 * @param handler Fetch handler
40 * @param val Define which val should open
41 */
42export function modifyFetchHandler(
43 handler: (req: Request) => Response | Promise<Response>,
44 { val, style }: { val?: ValRef; style?: string } = {},
52}
53
54export default modifyFetchHandler;
5
6app.get("/", async (c) => {
7 const response = await fetch("https://hacker-news.firebaseio.com/v0/topstories.json")
8 const storyIds = await response.json()
9
10 const storyResponse = await fetch(`https://hacker-news.firebaseio.com/v0/item/${storyIds[0]}.json`)
11 const story = await storyResponse.json()
12
22})
23
24export default app.fetch
5
6app.get("/", async (c) => {
7 const response = await fetch("https://hacker-news.firebaseio.com/v0/topstories.json")
8 const storyIds = await response.json()
9
10 const storyResponse = await fetch(`https://hacker-news.firebaseio.com/v0/item/${storyIds[0]}.json`)
11 const story = await storyResponse.json()
12
22})
23
24export default app.fetch
133 return new Response(body, { headers: { "Content-Type": "text/event-stream" } });
134});
135export default app.fetch;
133 return new Response(body, { headers: { "Content-Type": "text/event-stream" } });
134});
135export default app.fetch;
1/** @jsxImportSource https://esm.sh/react */
2import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
3
4const exampleJSX = <p>Hello, World!</p>;
5
6console.log(
7 await fetchText(import.meta.url, {
8 headers: {
9 "User-Agent": "", // can't include Deno, which on Val Town it would by default
4 return new Response(
5 (await parseFeed(
6 await (await fetch(
7 "https://xkcd.com/atom.xml",
8 )).text(),
5
6app.get("/", async (c) => {
7 const response = await fetch("https://hacker-news.firebaseio.com/v0/topstories.json");
8 const storyIds = await response.json();
9
10 const storyResponse = await fetch(`https://hacker-news.firebaseio.com/v0/item/${storyIds[0]}.json`);
11 const story = await storyResponse.json();
12
22});
23
24export default app.fetch;
16}
17
18// Function to fetch package info from NPM registry
19async function fetchPackageInfo(packageName: string) {
20 const url = `https://registry.npmjs.org/${packageName}`;
21 const response = await fetch(url);
22 if (!response.ok) {
23 throw new Error(`Failed to fetch package info for ${packageName}`);
24 }
25 return response.json();
45
46async function getGithubReleases(repo: string): Promise<GithubRelease[]> {
47 const response = await fetch(`https://api.github.com/repos/${repo}/releases`);
48 if (!response.ok) {
49 throw new Error(`Failed to fetch releases from ${repo}`);
50 }
51 return response.json();
76async function checkNpmUpdates(packageJsonUrl: string): Promise<string> {
77 try {
78 const response = await fetch(packageJsonUrl);
79 if (!response.ok) {
80 throw new Error(`Failed to fetch package.json from ${packageJsonUrl}`);
81 }
82 const packageJson: PackageJson = await response.json();
89 for (const [name, version] of Object.entries(dependencies)) {
90 try {
91 const packageInfo = await fetchPackageInfo(name);
92 const repoUrl = extractGitHubRepoUrl(packageInfo);
93 if (!repoUrl) {
114 for (const [name, version] of Object.entries(devDependencies)) {
115 try {
116 const packageInfo = await fetchPackageInfo(name);
117 const repoUrl = extractGitHubRepoUrl(packageInfo);
118 if (!repoUrl) {
178});
179
180export default app.fetch;
1/** @jsxImportSource https://esm.sh/hono@4.0.8/jsx **/
2
3import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
4import view_route from "https://esm.town/v/pomdtr/blob_admin_blob";
5import create_route from "https://esm.town/v/pomdtr/blob_admin_create";
133});
134
135export default modifyFetchHandler(passwordAuth(app.fetch));