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 }
10
11 useEffect(() => {
12 async function fetchWeather() {
13 try {
14 const response = await fetch(
15 `https://api.open-meteo.com/v1/forecast?latitude=${location.latitude}&longitude=${location.longitude}¤t_weather=true&hourly=temperature_2m,weathercode&daily=weathercode,temperature_2m_max,temperature_2m_min&timezone=auto`
16 );
18 setWeatherData(data);
19 } catch (err) {
20 setError("Could not fetch weather data");
21 }
22 }
23
24 fetchWeather();
25 }, [location]);
26
28 e.preventDefault();
29 try {
30 const response = await fetch(
31 `https://geocoding-api.open-meteo.com/v1/search?name=${cityName}&count=1&language=en&format=json`
32 );
51 setTrainingPlan("");
52 setYoutubeLinks([]);
53 const response = await fetch("/generate-training", {
54 method: "POST",
55 headers: { "Content-Type": "application/json", "Regenerate-Key": regenerateKey.toString() },
76 setSharing(true);
77 try {
78 const response = await fetch("/share-training", {
79 method: "POST",
80 headers: { "Content-Type": "application/json" },
718 const videoPlaceholders = trainingPlan.match(/\[VIDEO: .+?\]/g) || [];
719
720 // Fetch and embed YouTube videos
721 const youtubeLinks = [];
722 for (const placeholder of videoPlaceholders) {
809 try {
810 const searchUrl = `https://www.googleapis.com/youtube/v3/search?part=snippet&q=${encodeURIComponent(sport + ' ' + query)}&key=${apiKey}&type=video&maxResults=1`;
811 const response = await fetch(searchUrl);
812 const data = await response.json();
813 if (data.error) {
819 }
820 } catch (error) {
821 console.error("Error fetching from YouTube API:", error);
822 }
823 }
51 setTrainingPlan("");
52 setYoutubeLinks([]);
53 const response = await fetch("/generate-training", {
54 method: "POST",
55 headers: { "Content-Type": "application/json", "Regenerate-Key": regenerateKey.toString() },
76 setSharing(true);
77 try {
78 const response = await fetch("/share-training", {
79 method: "POST",
80 headers: { "Content-Type": "application/json" },
46
47 try {
48 const response = await fetch(mode === 'chat' ? '/chat' : '/generate-image', {
49 method: 'POST',
50 body: JSON.stringify({
233 const textAreaRef = useRef(null);
234
235 const fetchUniprotSequence = async () => {
236 if (!uniprotId.trim()) {
237 setError("Please enter a UniProt ID");
242 setError("");
243 setIsLoading(true);
244 const response = await fetch(`https://rest.uniprot.org/uniprotkb/${uniprotId}.fasta`);
245
246 if (!response.ok) {
254 setSequence(extractedSequence);
255 } catch (error) {
256 console.error("Error fetching UniProt sequence:", error);
257 setError(`Could not retrieve sequence for ${uniprotId}. Check UniProt ID.`);
258 } finally {
407 <div style={{ display: "flex", gap: "10px" }}>
408 <button
409 onClick={fetchUniprotSequence}
410 disabled={isLoading}
411 style={{ flex: 1 }}
412 >
413 {isLoading ? "Fetching..." : "Fetch Sequence"}
414 </button>
415 <select
540 {sequence ? renderSequence() : (
541 <p style={{ color: "#888" }}>
542 Enter or fetch a protein sequence to visualize
543 </p>
544 )}