9}
1011const response = await fetch(cacheUrl, {
12// Add timeout and other performance optimizations
13signal: AbortSignal.timeout(5000),
19
20if (!response.ok) {
21throw new Error('Failed to fetch zb.txt');
22}
2338return newResponse;
39} catch (error) {
40// If fetch fails, provide a fallback or error response
41return new Response(`Error retrieving zb.txt: ${error.message}`, {
42status: 500,
cerebras_coderindex.ts1 match
181182try {
183const response = await fetch("/", {
184method: "POST",
185body: JSON.stringify({
stevensDemosendDailyBrief.ts1 match
135const lastSunday = today.startOf("week").minus({ days: 1 });
136137// Fetch relevant memories using the utility function
138const memories = await getRelevantMemories();
139
stevensDemoNotebookView.tsx12 matches
67const [currentPage, setCurrentPage] = useState(1);
6869const fetchMemories = useCallback(async () => {
70setLoading(true);
71setError(null);
72try {
73const response = await fetch(API_BASE);
74if (!response.ok) {
75throw new Error(`HTTP error! status: ${response.status}`);
78setMemories(data);
79} catch (e) {
80console.error("Failed to fetch memories:", e);
81setError(e.message || "Failed to fetch memories.");
82} finally {
83setLoading(false);
8687useEffect(() => {
88fetchMemories();
89}, [fetchMemories]);
9091const handleAddMemory = async (e: React.FormEvent) => {
100101try {
102const response = await fetch(API_BASE, {
103method: "POST",
104headers: { "Content-Type": "application/json" },
112setNewMemoryTags("");
113setShowAddForm(false);
114await fetchMemories();
115} catch (e) {
116console.error("Failed to add memory:", e);
123124try {
125const response = await fetch(`${API_BASE}/${id}`, {
126method: "DELETE",
127});
129throw new Error(`HTTP error! status: ${response.status}`);
130}
131await fetchMemories();
132} catch (e) {
133console.error("Failed to delete memory:", e);
155156try {
157const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
158method: "PUT",
159headers: { "Content-Type": "application/json" },
164}
165setEditingMemory(null);
166await fetchMemories();
167} catch (e) {
168console.error("Failed to update memory:", e);
stevensDemoindex.ts2 matches
135));
136137// HTTP vals expect an exported "fetch handler"
138export default app.fetch;
stevensDemo.cursorrules5 matches
163```
1641655. **fetchTranspiledJavaScript** - Fetch and transpile TypeScript to JavaScript:
166```ts
167const jsCode = await fetchTranspiledJavaScript("https://esm.town/v/username/project/path/to/file.ts");
168```
169242243// Inject data to avoid extra round-trips
244const initialData = await fetchInitialData();
245const dataScript = `<script>
246window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
3003015. **API Design:**
302- `fetch` handler is the entry point for HTTP vals
303- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
304- Properly handle CORS if needed for external access
stevensDemoApp.tsx17 matches
82const [cookieAndTeaMode, setCookieAndTeaMode] = useState(false);
8384// Fetch images from backend instead of blob storage directly
85useEffect(() => {
86// Set default background color in case image doesn't load
89}
9091// Fetch avatar image
92fetch("/api/images/stevens.jpg")
93.then((response) => {
94if (response.ok) return response.blob();
103});
104105// Fetch wood background
106fetch("/api/images/wood.jpg")
107.then((response) => {
108if (response.ok) return response.blob();
129}, []);
130131const fetchMemories = useCallback(async () => {
132setLoading(true);
133setError(null);
134try {
135const response = await fetch(API_BASE);
136if (!response.ok) {
137throw new Error(`HTTP error! status: ${response.status}`);
154}
155} catch (e) {
156console.error("Failed to fetch memories:", e);
157setError(e.message || "Failed to fetch memories.");
158} finally {
159setLoading(false);
162163useEffect(() => {
164fetchMemories();
165}, [fetchMemories]);
166167const handleAddMemory = async (e: React.FormEvent) => {
176177try {
178const response = await fetch(API_BASE, {
179method: "POST",
180headers: { "Content-Type": "application/json" },
188setNewMemoryTags("");
189setShowAddForm(false);
190await fetchMemories();
191} catch (e) {
192console.error("Failed to add memory:", e);
199200try {
201const response = await fetch(`${API_BASE}/${id}`, {
202method: "DELETE",
203});
205throw new Error(`HTTP error! status: ${response.status}`);
206}
207await fetchMemories();
208} catch (e) {
209console.error("Failed to delete memory:", e);
231232try {
233const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
234method: "PUT",
235headers: { "Content-Type": "application/json" },
240}
241setEditingMemory(null);
242await fetchMemories();
243} catch (e) {
244console.error("Failed to update memory:", e);
NowPlayingmain.tsx2 matches
12const basic = Buffer.from(`${client_id}:${client_secret}`).toString("base64");
1314const response = await fetch(TOKEN_ENDPOINT, {
15method: "POST",
16headers: {
31const { access_token } = await getAccessToken(client_id, client_secret, refresh_token);
3233const response = await fetch(NOW_PLAYING_ENDPOINT, {
34headers: {
35Authorization: `Bearer ${access_token}`,
3233useEffect(() => {
34fetchContributions();
35}, []);
3637const fetchContributions = async () => {
38setError(null);
39setContributionData(null);
40setUserData(null);
41try {
42const response = await fetch("/contributions", {
43method: "POST",
44headers: { "Content-Type": "application/json" },
45body: JSON.stringify({ username }),
46});
47if (!response.ok) throw new Error("Failed to fetch contributions");
48const data = await response.json();
49console.log("Fetched data:", data);
50setContributionData(data.contributionCalendar);
51setUserData(data.user);
52} catch (err) {
53console.error("Error fetching contributions:", err);
54setError(err.message);
55}
248const handleKeyPress = (event) => {
249if (event.key === "Enter") {
250fetchContributions();
251}
252};
272placeholder="Enter GitHub username"
273/>
274<button onClick={fetchContributions}>Fetch Commits</button>
275</div>
276{error && <p className="error">{error}</p>}
331if (request.method === "POST" && new URL(request.url).pathname === "/contributions") {
332const { username } = await request.json();
333const contributionData = await fetchGitHubContributions(username);
334return new Response(JSON.stringify(contributionData), {
335headers: { "Content-Type": "application/json" },
359}
360361async function fetchGitHubContributions(username: string) {
362const query = `
363query($username: String!) {
381`;
382383const response = await fetch("https://api.github.com/graphql", {
384method: "POST",
385headers: {
391392if (!response.ok) {
393throw new Error("Failed to fetch GitHub data");
394}
395
moiPosterImprovedindex.ts12 matches
55}
5657// Fetch authenticated user info
58const { data: user } = await vt.me.retrieve();
59if (!user) {
72});
73} catch (error) {
74console.error("Error fetching user info:", error);
75// Check for specific auth errors if vt was instantiated
76if (error.message && (error.message.includes("401") || error.message.includes("Unauthorized"))) {
77return c.json({ error: "Authentication failed. Please check your API Key." }, 401);
78}
79return c.json({ error: "Failed to fetch user info", details: error.message }, 500);
80}
81});
95return c.json({ username: user.username });
96} catch (error) {
97console.error(`Error fetching user by username ${username}:`, error);
98return c.json({ error: "Username not found", details: error.message }, 404);
99}
105return c.json({ username: user.username });
106} catch (error) {
107console.error(`Error fetching user by username ${username}:`, error);
108return c.json({ error: "Username not found", details: error.message }, 404);
109}
110} catch (error) {
111console.error("Error in /api/username/:username:", error);
112return c.json({ error: "Failed to fetch username", details: error.message }, 500);
113}
114});
175return c.json(valsWithEndpoints);
176} catch (error) {
177console.error("Error fetching vals:", error);
178// Check for specific auth errors if vt was instantiated
179if (error.message && (error.message.includes("401") || error.message.includes("Unauthorized"))) {
180return c.json({ error: "Authentication failed. Please check your API Key." }, 401);
181}
182return c.json({ error: "Failed to fetch vals", details: error.message }, 500);
183}
184});
262);
263} else {
264// Fallback default if val details couldn't be fetched
265result.content = "---\ntitle: \"Unknown Val\"\ndescription: \"Could not load val details.\"\ntags: [\"val-town\"]\n---\n\n## About\n\nDetails for this val could not be loaded. It might be private or deleted.\n";
266}
270271} catch (error) {
272console.error(`Top-level error fetching val moi.md for ${c.req.param("valId")}:`, error);
273return c.json({ error: "Failed to fetch moi.md", details: error.message }, 500);
274}
275});
453});
454455export default app.fetch;