forky_1745421053035App.tsx1 match
25}
2627const response = await fetch(`/fork?url=${encodeURIComponent(projectUrl)}`, {
28method: "POST",
29headers: {
forky_1745421053035index.ts2 matches
232});
233234// HTTP vals expect an exported "fetch handler"
235// This is how you "run the server" in Val Town with Hono
236export default app.fetch;
forky_1745421027624App.tsx1 match
25}
2627const response = await fetch(`/fork?url=${encodeURIComponent(projectUrl)}`, {
28method: "POST",
29headers: {
forky_1745421027624index.ts2 matches
232});
233234// HTTP vals expect an exported "fetch handler"
235// This is how you "run the server" in Val Town with Hono
236export default app.fetch;
910// Proxy the request to the old blog
11const response = await fetch(
12new Request(OLD_BLOG_URL + url.pathname + url.search, {
13method: c.req.method,
vt-blog-1live-reload.ts3 matches
3233/**
34* Creates a wrapper around a fetch handler that injects a script tag into HTML responses
35*
36* @param handler The original fetch handler function
37* @param scriptContent The HTML content to inject
38* @returns A new fetch handler with HTML rewriting capability
39*/
40export function injectHTML(
34});
3536// Export the fetch handler for Val Town
37export default liveReload(app.fetch, import.meta.url);
vt-blog-12025-04-08-migration.md2 matches
83We didn't. We left them where they are, and proxy to them.
8485Writing a proxy in Val Town (or any functions platform with the ['fetch handler' interface](https://blog.val.town/blog/the-api-we-forgot-to-name/)) is a delight:
8687```ts
89export async function proxy(req: Request): Promise<Response> {
90const url = new URL(req.url);
91return fetch(OLD_BLOG_HOST + url.pathname + url.search, {
92method: req.method,
93headers: req.headers,
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);