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 }
3Proxied web browser for debugging new DNS records
4
5It's difficult to verify new DNS records. If you check too early, the old records may get cached on your computer, browser, or local network. This tool uses a proxied fetch so you can always view your web page uncached.
6
7Uses @std/fetch on the backend to ensure the DNS records of the request are from new places every request.
8
9Version 4 of this val also showed DNS records, pulled on the server,
62
63 useEffect(() => {
64 const fetchYCCompanies = async () => {
65 const storedCompanies = localStorage.getItem("ycCompanies");
66 if (storedCompanies) {
69 setDebugInfo(prevInfo => prevInfo + `\nLoaded ${companies.length} companies from localStorage`);
70 } else {
71 const response = await fetch("/companies.json");
72 const companies = await response.json();
73 setYcCompanies(companies);
74 localStorage.setItem("ycCompanies", JSON.stringify(companies));
75 setDebugInfo(prevInfo =>
76 prevInfo + `\nFetched ${companies.length} companies from server and stored in localStorage`
77 );
78 }
79 };
80 fetchYCCompanies();
81 }, []);
82
226
227export default async function server(request: Request): Promise<Response> {
228 const companies = await fetch("https://stevekrouse-yc_database.web.val.run").then(res => res.json());
229 const url = new URL(request.url);
230 if (url.pathname === "/companies.json") {
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";
137});
138
139export default modifyFetchHandler(passwordAuth(app.fetch));
17
18 try {
19 const response = await fetch(window.location.href, {
20 method: "POST",
21 headers: {
134
135 console.log("Sending initial request to Replicate...");
136 const response = await fetch(`https://api.replicate.com/v1/models/${modelVersion}/predictions`, {
137 method: "POST",
138 headers: {
157 while (true) {
158 console.log("Checking result...");
159 const resultResponse = await fetch(prediction.urls.get, {
160 headers: {
161 "Authorization": `Token ${REPLICATE_API_KEY}`,
187 const imageName = `generated-image-${timestamp}.jpg`;
188
189 const imageResponse = await fetch(imageUrl);
190 if (!imageResponse.ok) throw new Error("Failed to download image");
191
206 const imageName = `generated-image-${timestamp}.jpg`;
207
208 const imageResponse = await fetch(imageUrl);
209 if (!imageResponse.ok) throw new Error("Failed to generate image");
210
17
18 try {
19 const response = await fetch(window.location.href, {
20 method: "POST",
21 headers: { "Content-Type": "application/json" },
102
103 console.log("Sending initial request to Replicate...");
104 const response = await fetch(`https://api.replicate.com/v1/models/${modelVersion}/predictions`, {
105 method: "POST",
106 headers: {
125 while (true) {
126 console.log("Checking result...");
127 const resultResponse = await fetch(prediction.urls.get, {
128 headers: {
129 "Authorization": `Token ${REPLICATE_API_KEY}`,
155 const imageName = `generated-image-${timestamp}.jpg`;
156
157 const imageResponse = await fetch(imageUrl);
158 if (!imageResponse.ok) throw new Error("Failed to download image");
159
174 const imageName = `generated-image-${timestamp}.jpg`;
175
176 const imageResponse = await fetch(imageUrl);
177 if (!imageResponse.ok) throw new Error("Failed to generate image");
178
24
25 console.log("Sending initial request to Replicate...");
26 const response = await fetch(`https://api.replicate.com/v1/models/${modelVersion}/predictions`, {
27 method: "POST",
28 headers: {
47 while (true) {
48 console.log("Checking result...");
49 const resultResponse = await fetch(prediction.urls.get, {
50 headers: {
51 "Authorization": `Token ${REPLICATE_API_KEY}`,
77 const imageName = `generated-image-${timestamp}.jpg`;
78
79 const imageResponse = await fetch(imageUrl);
80 if (!imageResponse.ok) throw new Error("Failed to download image");
81
96 const imageName = `generated-image-${timestamp}.jpg`;
97
98 const imageResponse = await fetch(imageUrl);
99 if (!imageResponse.ok) throw new Error("Failed to generate image");
100
28async function getMostPopularPinterestImage(query: string): Promise<string> {
29 const searchUrl = `https://api.pinterest.com/v5/search/pins?query=${encodeURIComponent(query)}&page_size=50&sort_order=popularity`;
30 const response = await fetch(searchUrl, {
31 headers: {
32 "Accept-Language": "en-US",
3### Why
4I'm using this val for my 3-color e-ink display run by a Raspberry Pi Zero W. The Pi runs a cron job that tell's it
5to fetch this url twice a day and render it to the display. Works like a charm.
6
7Right now I'm not displaying much but I'm going to keep iterating on what type of information I want to display.
7 `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t_weather=true&temperature_unit=fahrenheit`;
8 try {
9 const response = await fetch(url);
10 if (!response.ok) {
11 throw new Error(`Weather API responded with status: ${response.status}`);
15 return data.current_weather;
16 } catch (error) {
17 console.error("Error fetching weather:", error);
18 return null;
19 }
135 </div>
136 )
137 : <div className="weather-info">Unable to fetch weather data</div>}
138 </div>
139 </body>
149
150 try {
151 const response = await fetch(url);
152 if (!response.ok) {
153 throw new Error(`APIFlash responded with status: ${response.status}`);