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);
1import { fetch } from "https://esm.town/v/std/fetch";
23// --- Core Interfaces --- (No changes)
12011202try {
1203const res = await fetch(window.location.pathname, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(initialPayload) });
1204const data = await res.json();
1205console.log("Received response:", data);
12651266} catch (err) {
1267console.error("Fetch Error:", err);
1268resultBox.textContent = 'Network or Client-Side Error: ' + err.message;
1269resultBox.className = 'error';
1import { fetch } from "https://esm.town/v/std/fetch";
23// --- Core Interfaces --- (No changes)
11921193try {
1194const res = await fetch(window.location.pathname, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(initialPayload) });
1195const data = await res.json();
1196console.log("Received response:", data);
12301231} catch (err) {
1232console.error("Fetch Error:", err);
1233resultBox.textContent = 'Network or Client-Side Error: ' + err.message;
1234resultBox.className = 'error';
live-reload5demo.tsx1 match
63});
6465export default liveReload(app.fetch, import.meta.url);
live-reload4demo.tsx1 match
40});
4142export default liveReload(app.fetch, import.meta.url);
live-reload5utils.ts3 matches
93}
94/**
95* Creates a wrapper around a fetch handler that injects an HTML string
96* into the document. It first checks for a <body> tag; if missing,
97* it looks for an <html> tag. If neither are present, it appends to
98* the full text response.
99*
100* @param handler The original fetch handler function
101* @param html The HTML content to inject
102* @returns A new fetch handler with HTML rewriting
103*/
104export function injectHTML(
live-reload5README.md2 matches
20import { liveReload } from "https://esm.town/v/stevekrouse/live-reload/main.ts";
2122const handler = (req: Request) => { /* your fetch handler */}
23export default liveReload(handler, import.meta.url);
24```
5960// Enable live reloading
61export default liveReload(app.fetch, import.meta.url);
62```
63
live-reload5error-proxy.ts1 match
7return new Response(`Learn more at https://www.val.town/x/stevekrouse/live-reload`);
8}
9const resp = await fetch(targetURL, {
10headers: req.headers,
11});