23});
2425// HTTP vals expect an exported "fetch handler"
26// This is how you "run the server" in Val Town with Hono
27export default app.fetch;
stevennssendDailyBrief.ts1 match
135const lastSunday = today.startOf("week").minus({ days: 1 });
136137// Fetch relevant memories using the utility function
138const memories = await getRelevantMemories();
139
stevennsNotebookView.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);
135));
136137// HTTP vals expect an exported "fetch handler"
138export default app.fetch;
stevenns.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
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);
107* errorInvalidFile: "Invalid file type. Please upload a {{document_format_accepted | default('PDF')}}.",
108* errorFileSize: "File is too large (Max {{max_pdf_size_mb}}MB).",
109* errorFetchFailed: "Failed to perform analysis: {{errorMessage}}",
110* contactNamePlaceholder: "{{app_config.contact_form_placeholders_en.name}}",
111* contactEmailPlaceholder: "{{app_config.contact_form_placeholders_en.email}}",
135* errorInvalidFile: "Tipo de archivo inválido. Por favor, suba un {{document_format_accepted | default('PDF')}}.",
136* errorFileSize: "El archivo es demasiado grande (Máx {{max_pdf_size_mb}}MB).",
137* errorFetchFailed: "Falló la realización del análisis: {{errorMessage}}",
138* contactNamePlaceholder: "{{app_config.contact_form_placeholders_es.name}}",
139* contactEmailPlaceholder: "{{app_config.contact_form_placeholders_es.email}}",
574575try {
576const response = await fetch(window.location.pathname + '?format=json', { method: 'POST', headers: { 'Accept': 'application/json'}, body: formData });
577const data = await response.json();
578if (!response.ok) { throw new Error(data?.error || data?.details || response.statusText || \`Server status: \${response.status}\`); }
641const { OpenAI } = await import("https://esm.town/v/std/openai");
642// const { z } = await import("npm:zod"); // Zod might be optional if config is trusted
643const { fetch } = await import("https://esm.town/v/std/fetch");
644const { PDFExtract, PDFExtractOptions } = await import("npm:pdf.js-extract");
645
8384try {
85const response = await fetch(searchUrl, {
86headers: {
87// Minimal headers to mimic a browser
133}
134135const response = await fetch(properUrl, {
136headers: { "User-Agent": "Mozilla/5.0 ValTownLeadGen/1.0" },
137signal: AbortSignal.timeout(10000),
138}); // 10s timeout
139if (!response.ok) {
140console.warn(`Failed to fetch ${properUrl} for lead ${leadId}: ${response.status}`);
141await updateLeadStatus(leadId, "error_scraping_fetch", {}, `HTTP ${response.status} for ${properUrl}`);
142return null;
143}
380.status-pending, .status-processing_search, .status-processing_leads { background-color: #ffc107; color: #212529;}
381.status-completed { background-color: #28a745; }
382.status-failed_config, .status-error_searching, .status-completed_no_sites, .status-error_scraping, .status-error_drafting, .status-error_scraping_fetch, .status-error_drafting_empty_response, .status-failed_uncaught_exception { background-color: #dc3545; }
383.status-email_extracted, .status-email_drafted { background-color: #17a2b8; }
384.status-no_email_found, .status-pending_scrape { background-color: #6c757d; }
484metrics.total = leads.length;
485metrics.emailFound = leads.filter(l =>
486l.email_address && l.status !== "error_scraping_fetch" && l.status !== "error_scraping"
487).length;
488metrics.emailDrafted = leads.filter(l => l.drafted_email_body && l.status !== "error_drafting").length;
493}
494} catch (e) {
495console.error("Error fetching data for UI:", e);
496generalError = `Error loading data: ${e.message}`;
497}
613614// Corrected export for Val Town
615export default app.fetch;
1try {
2const response = await fetch(
3"https://trojan-square-embedder.onrender.com/embed",
4{
MiniAppStarterneynar.ts14 matches
1const baseUrl = "https://api.neynar.com/v2/farcaster/";
23export async function fetchNeynarGet(path: string) {
4const res = await fetch(baseUrl + path, {
5method: "GET",
6headers: {
14}
1516export function fetchUser(username: string) {
17return fetchNeynarGet(`user/by_username?username=${username}`).then(r => r.user);
18}
19export function fetchUsersById(fids: string) {
20return fetchNeynarGet(`user/bulk?fids=${fids}`).then(r => r.users);
21}
2223export function fetchUserFeed(fid: number) {
24return fetchNeynarGet(
25`feed?feed_type=filter&filter_type=fids&fids=${fid}&with_recasts=false&with_replies=false&limit=100&cursor=`,
26).then(r => r.casts);
27}
2829export function fetchChannel(channelId: string) {
30return fetchNeynarGet(`channel?id=${channelId}`).then(r => r.channel);
31}
3233export function fetchChannelFeed(channelId: string) {
34return fetchNeynarGet(
35`feed/channels?channel_ids=${channelId}&with_recasts=false&limit=100`,
36).then(r => r.casts);
37}
3839export function fetchChannelsFeed(channelIds: array) {
40return fetchNeynarGet(
41`feed/channels?channel_ids=${channelIds.join(",")}&with_recasts=false&limit=100`,
42).then(r => r.casts);