25 }
26
27 // Fetch current comments
28 const comments = await blob.getJSON<string[]>(key) ?? [];
29
30
31export default async function main(req: Request): Promise<Response> {
32 // Fetch existing comments
33 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
34
64});
65
66export default app.fetch;
67
58app.post("/comment", async c => {
59 const formData = await c.req.parseBody();
60 const text = formData.get('text'); // using get method to fetch the value
61
62 // Insert the comment into the database
67});
68
69export default app.fetch;
70
69});
70
71export default app.fetch;
72
71});
72
73export default app.fetch;
74
75
68});
69
70export default app.fetch;
71
35 }
36
37 // Fetch all comments from the database
38 const comments = await sqlite.all("SELECT content, created_at FROM comments ORDER BY created_at DESC");
39
21const app = new Hono();
22
23// Helper function to fetch all comments from the database
24async function fetchComments() {
25 const result = await sqlite.execute(`SELECT * FROM comments ORDER BY timestamp DESC`);
26 return result.rows;
29// Main route: serves the HTML form and displays comments
30app.get("/", async (c) => {
31 const comments = await fetchComments();
32 const commentsHTML = comments.map(
33 (row) => `<div><strong>${row[1]}</strong> (${row[3]}): <p>${row[2]}</p></div>`
76});
77
78// Export the fetch handler to be used by the runtime
79export default app.fetch;
80
64});
65
66export default app.fetch;
67