10app.get("/", async (c) => c.html(await sqlite_admin_tables()));
11app.get("/:table", async (c) => c.html(await sqlite_admin_table(c.req.param("table"))));
12export default basicAuth(app.fetch, { verifyUser: (_, password) => verifyToken(password) });
1import { email } from "https://esm.town/v/std/email?v=9";
2
3// Fetches a random joke.
4function fetchRandomJoke() {
5 const response = fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
9}
10
11const randomJoke = fetchRandomJoke();
12const setup = randomJoke.setup;
13const punchline = randomJoke.punchline;
14 start = performance.now();
15 try {
16 const res = await fetch(url);
17 end = performance.now();
18 status = res.status;
25 } catch (e) {
26 end = performance.now();
27 reason = `couldn't fetch: ${e}`;
28 ok = false;
29 console.log(`Website down (${url}): ${reason} (${end - start}ms)`);
1// ... imports ...
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
9}
10
11const randomJoke = await fetchRandomJoke();
12const setup = randomJoke.setup;
13const punchline = randomJoke.punchline;
16// --------------------------
17
18async function fetchNews(queries: any, hours: number, lang: string, region: string) {
19 let news;
20 let results = [];
103export default async function(interval: Interval) {
104 try {
105 const results = await fetchNews(queries, hours, lang, region);
106 console.log(`${
107 results.map(q => {
41 { query, hours, lang, region }: { query: string; hours: number; lang: string; region: string },
42) {
43 const response = await fetch(
44 getFeedUrl(query, hours, lang, region),
45 );
9
10 useEffect(() => {
11 async function fetchWeather() {
12 try {
13 // Los Angeles coordinates with Fahrenheit units
14 const response = await fetch(
15 "https://api.open-meteo.com/v1/forecast?latitude=34.0522&longitude=-118.2437¤t=temperature_2m,relative_humidity_2m,wind_speed_10m,weather_code&temperature_unit=fahrenheit&wind_speed_unit=mph&timezone=America%2FLos_Angeles"
16 );
17
18 if (!response.ok) {
19 throw new Error('Weather data fetch failed');
20 }
21
29 }
30
31 fetchWeather();
32 }, []);
33
34
35
36export default app.fetch;
14 start = performance.now();
15 try {
16 const res = await fetch(url);
17 end = performance.now();
18 status = res.status;
25 } catch (e) {
26 end = performance.now();
27 reason = `couldn't fetch: ${e}`;
28 ok = false;
29 console.log(`Website down (${url}): ${reason} (${end - start}ms)`);
9 const handleSubmit = async (e: React.FormEvent) => {
10 e.preventDefault();
11 const response = await fetch(`/proxy?url=${encodeURIComponent(url)}`);
12 const html = await response.text();
13 setContent(html);
19 <p>
20 It's difficult to check new DNS records, because old records may be cached on your computer, browser, or local
21 network. This tool uses <a href="https://docs.val.town/std/fetch" target="_blank">a proxied fetch</a>{" "}
22 so you can always view your web page uncached.
23 </p>
60
61export default async function server(request: Request): Promise<Response> {
62 const { fetch } = await import("https://esm.town/v/std/fetch");
63
64 const url = new URL(request.url);
71
72 try {
73 const proxyResponse = await fetch(targetUrl);
74 const content = await proxyResponse.text();
75 return new Response(content, {
77 });
78 } catch (error) {
79 return new Response("Error fetching the URL", { status: 500 });
80 }
81 }