25 for (const source of NEWS_SOURCES) {
26 try {
27 const response = await fetch(source);
28 const html = await response.text();
29
64 }
65 } catch (sourceError) {
66 console.error(`Error fetching news from ${source}: ${sourceError}`);
67 }
68 }
11 e.preventDefault();
12 try {
13 const result = await fetch("/process", {
14 method: "POST",
15 body: JSON.stringify({ query })
11
12 try {
13 const response = await fetch("/messages", {
14 method: "POST",
15 headers: { "Content-Type": "application/json" },
60});
61
62// HTTP vals expect an exported "fetch handler"
63// This is how you "run the server" in Val Town with Hono
64export default app.fetch;
9 const [messages, setMessages] = React.useState(initialMessages);
10
11 const fetchMessages = async () => {
12 try {
13 const response = await fetch("/messages");
14 const data = await response.json();
15 setMessages(data.reverse());
16 } catch (error) {
17 console.error("Failed to fetch messages", error);
18 }
19 };
23 <h1>💬 Message Board</h1>
24 <MessageList messages={messages} />
25 <MessageInput onSubmit={fetchMessages} />
26 {thisProjectURL
27 ? (
5async function servePublicFile(path: string): Promise<Response> {
6 const url = new URL("./public/" + path, import.meta.url);
7 const text = await (await fetch(url, {
8 headers: {
9 "User-Agent": "", // to transpile TS to JS
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({
162 const handleVoiceInput = async (transcript) => {
163 try {
164 const response = await fetch("/generate", {
165 method: "POST",
166 body: JSON.stringify({
207 window.speechSynthesis.speak(utterance);
208 } else {
209 fetch("/speak", {
210 method: "POST",
211 body: JSON.stringify({ text }),
318 }`;
319
320 const ttsResponse = await fetch(ttsUrl, {
321 headers: {
322 "User-Agent":
38
39 try {
40 const response = await fetch("/chat", {
41 method: "POST",
42 body: JSON.stringify({ messages: newMessages, mode }),
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 })));