59});
60
61export default app.fetch;
9
10 // Proxy the request to the old blog
11 const response = await fetch(
12 new Request(OLD_BLOG_URL + url.pathname + url.search, {
13 method: c.req.method,
32
33/**
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(
39});
40
41// Export the fetch handler for Val Town
42export default liveReload(app.fetch, import.meta.url);
83We didn't. We left them where they are, and proxy to them.
84
85Writing 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:
86
87```ts
89export async function proxy(req: Request): Promise<Response> {
90 const url = new URL(req.url);
91 return fetch(OLD_BLOG_HOST + url.pathname + url.search, {
92 method: req.method,
93 headers: req.headers,
380app.get("/shared/*", (c) => serveFile(c.req.path, import.meta.url));
381
382export default app.fetch;
1/** @jsxImportSource npm:hono/jsx **/
2
3import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
4import { iframeHandler } from "https://esm.town/v/nbbaier/iframeHandler";
5import { resetStyle } from "https://esm.town/v/nbbaier/resetStyle";
16import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken";
17import { ResultSet, sqlite } from "https://esm.town/v/std/sqlite";
18import { reloadOnSaveFetchMiddleware } from "https://esm.town/v/stevekrouse/reloadOnSave";
19import { Hono } from "npm:hono";
20import type { FC } from "npm:hono/jsx";
175});
176
177export const handler = app.fetch;
178export default iframeHandler(modifyFetchHandler(passwordAuth(handler, { verifyPassword: verifyToken })));
150 return c.html(html);
151 } catch (error) {
152 return c.text(`Error fetching logs: ${error.message}`, 500);
153 }
154});
198});
199
200export default app.fetch;
51const app = new Hono();
52app.get("/", HTTP101);
53export default app.fetch;
29 if (!threadId || threadId === "") {
30 console.log("Creating new thread...");
31 const threadResponse = await fetch("https://api.openai.com/v1/threads", {
32 method: "POST",
33 headers: {
51 // Add message and run assistant
52 console.log("Running assistant...");
53 const runResponse = await fetch(`https://api.openai.com/v1/threads/${threadId}/runs`, {
54 method: "POST",
55 headers: {
86 await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
87
88 const statusResponse = await fetch(
89 `https://api.openai.com/v1/threads/${threadId}/runs/${runId}`,
90 {
113 // Get the assistant's response
114 console.log("Getting messages...");
115 const messagesResponse = await fetch(
116 `https://api.openai.com/v1/threads/${threadId}/messages?order=desc&limit=1`,
117 {