90
91 try {
92 const response = await fetch('/chat', {
93 method: 'POST',
94 headers: { 'Content-Type': 'application/json' },
11
12 constructor() {}
13 async fetch(req: Request): Promise<Response> {
14 if (new URL(req.url).pathname === "/robots.txt") {
15 return new Response("User-agent: *\nDisallow: /");
234const sc = new StaticChess();
235
236export default analyticsHandlerWrapper(sc.fetch.bind(sc));
10 const handleSubmit = async (e) => {
11 e.preventDefault();
12 const response = await fetch("/jobs", {
13 method: "POST",
14 headers: { "Content-Type": "application/json" },
55
56 useEffect(() => {
57 fetchMessages();
58 const interval = setInterval(fetchMessages, 5000);
59 return () => clearInterval(interval);
60 }, []);
61
62 const fetchMessages = async () => {
63 const response = await fetch("/messages");
64 if (response.ok) {
65 const data = await response.json();
70 const sendMessage = async (e) => {
71 e.preventDefault();
72 const response = await fetch("/messages", {
73 method: "POST",
74 headers: { "Content-Type": "application/json" },
77 if (response.ok) {
78 setNewMessage("");
79 fetchMessages();
80 }
81 };
107 const [jobs, setJobs] = useState([]);
108
109 const fetchJobs = async () => {
110 const response = await fetch("/jobs");
111 if (response.ok) {
112 const data = await response.json();
116
117 useEffect(() => {
118 fetchJobs();
119 }, []);
120
125 <div className="job-section">
126 <h2>Post a Job</h2>
127 <JobPostingForm onSubmit={fetchJobs} />
128 <div className="job-list">
129 <h2>Current Openings</h2>
59 }
60
61 // Fetch and process birthdays
62 const result = await sqlite.execute(`
63 SELECT name, birthday, email, reminder_days
239
240 // Inject data to avoid extra round-trips
241 const initialData = await fetchInitialData();
242 const dataScript = `<script>
243 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
286
2875. **API Design:**
288 - `fetch` handler is the entry point for HTTP vals
289 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
290
291
16
17 useEffect(() => {
18 fetchDailyPrompt();
19 }, []);
20
21 async function fetchDailyPrompt() {
22 try {
23 const response = await fetch("/get-daily-prompt");
24 const data = await response.json();
25 setPrompt(data.prompt);
26 } catch (error) {
27 console.error("Error fetching prompt:", error);
28 }
29 }
33 try {
34 // Track mood on server
35 await fetch("/track-mood", {
36 method: "POST",
37 body: JSON.stringify({ mood: moodLevel }),
39
40 // Get initial companion response based on mood
41 const response = await fetch("/initial-mood-response", {
42 method: "POST",
43 body: JSON.stringify({ mood: moodLevel }),
75
76 try {
77 const response = await fetch("/companion-chat", {
78 method: "POST",
79 body: JSON.stringify({
135
136 try {
137 const response = await fetch("/upload-voice-note", {
138 method: "POST",
139 body: formData,
149
150 // Transcribe and get companion response
151 const transcribeResponse = await fetch("/transcribe-voice", {
152 method: "POST",
153 body: formData,
156
157 // Companion responds to transcribed text
158 const companionResponse = await fetch("/companion-chat", {
159 method: "POST",
160 body: JSON.stringify({ prompt: transcribeData.transcription }),
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({
10
11 useEffect(() => {
12 fetchSuggestions();
13 fetchMessages();
14 }, []);
15
16 const fetchSuggestions = async () => {
17 const response = await fetch("/suggestions");
18 const data = await response.json();
19 setSuggestions(data);
20 };
21
22 const fetchMessages = async () => {
23 const response = await fetch("/messages");
24 const data = await response.json();
25 setChatMessages(data);
28 const handleSuggestionSubmit = async (e) => {
29 e.preventDefault();
30 await fetch("/suggestions", {
31 method: "POST",
32 headers: { "Content-Type": "application/json" },
34 });
35 setNewSuggestion({ title: "", description: "" });
36 fetchSuggestions();
37 };
38
39 const handleMessageSubmit = async (e) => {
40 e.preventDefault();
41 await fetch("/messages", {
42 method: "POST",
43 headers: { "Content-Type": "application/json" },
45 });
46 setNewMessage("");
47 fetchMessages();
48 };
49
3import React, { useEffect, useRef, useState } from "https://esm.sh/react@18.2.0";
4
5// Trivia questions (can be expanded or fetched from an API later)
6const TRIVIA_QUESTIONS = [
7 {
1import addCreation from "./addCreation";
2import fetchCreations from "./fetchCreations";
3import getCreation from "./getCreation";
4import updateTable from "./updateTable";
13 return getCreation(req);
14 if (req.method == "GET" && url.pathname == "/creations")
15 return fetchCreations(req);
16 if (req.method == "POST" && url.pathname == "/updateTable")
17 return updateTable(req);