untitled-6580README.md5 matches
32```
3334## API Endpoints
3536- `GET /api/products` - Get all products
37- `POST /api/products` - Create a new product
38- `GET /api/chat/messages` - Get chat messages
39- `POST /api/chat/messages` - Send a chat message
4041## Database Schema
untitled-6073index.ts2 matches
15await createTasksTable();
1617// API routes
18app.route("/api/tasks", tasks);
1920// Serve static files
167
168try {
169const response = await fetch('/api/generate-poem', {
170method: 'POST',
171headers: {
untitled-6073App.tsx12 matches
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { useState, useEffect } from "https://esm.sh/react@18.2.0";
3import type { Task, ApiResponse, CreateTaskRequest, UpdateTaskRequest } from "../../shared/types.ts";
4import TaskForm from "./TaskForm.tsx";
5import TaskItem from "./TaskItem.tsx";
17const [filter, setFilter] = useState<'all' | 'active' | 'completed'>('all');
1819// Load initial tasks from server-side injection or fetch from API
20useEffect(() => {
21if (window.__INITIAL_TASKS__) {
30setLoading(true);
31setError(null);
32const response = await fetch('/api/tasks');
33const result: ApiResponse<Task[]> = await response.json();
34
35if (result.success && result.data) {
48try {
49setError(null);
50const response = await fetch('/api/tasks', {
51method: 'POST',
52headers: { 'Content-Type': 'application/json' },
54});
55
56const result: ApiResponse<Task> = await response.json();
57
58if (result.success && result.data) {
69try {
70setError(null);
71const response = await fetch(`/api/tasks/${id}`, {
72method: 'PUT',
73headers: { 'Content-Type': 'application/json' },
75});
76
77const result: ApiResponse<Task> = await response.json();
78
79if (result.success && result.data) {
92try {
93setError(null);
94const response = await fetch(`/api/tasks/${id}`, {
95method: 'PUT',
96headers: { 'Content-Type': 'application/json' },
98});
99
100const result: ApiResponse<Task> = await response.json();
101
102if (result.success && result.data) {
115try {
116setError(null);
117const response = await fetch(`/api/tasks/${id}`, {
118method: 'DELETE',
119});
120
121const result: ApiResponse<{ deleted: boolean }> = await response.json();
122
123if (result.success) {
untitled-6073tasks.ts19 matches
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { getAllTasks, getTaskById, createTask, updateTask, deleteTask } from "../database/queries.ts";
3import type { CreateTaskRequest, UpdateTaskRequest, ApiResponse } from "../../shared/types.ts";
45const tasks = new Hono();
9try {
10const allTasks = await getAllTasks();
11return c.json({ success: true, data: allTasks } as ApiResponse<typeof allTasks>);
12} catch (error) {
13return c.json({ success: false, error: "Failed to fetch tasks" } as ApiResponse<never>, 500);
14}
15});
20const id = parseInt(c.req.param("id"));
21if (isNaN(id)) {
22return c.json({ success: false, error: "Invalid task ID" } as ApiResponse<never>, 400);
23}
24
25const task = await getTaskById(id);
26if (!task) {
27return c.json({ success: false, error: "Task not found" } as ApiResponse<never>, 404);
28}
29
30return c.json({ success: true, data: task } as ApiResponse<typeof task>);
31} catch (error) {
32return c.json({ success: false, error: "Failed to fetch task" } as ApiResponse<never>, 500);
33}
34});
40
41if (!body.title || body.title.trim().length === 0) {
42return c.json({ success: false, error: "Task title is required" } as ApiResponse<never>, 400);
43}
44
45const newTask = await createTask({ title: body.title.trim() });
46return c.json({ success: true, data: newTask } as ApiResponse<typeof newTask>, 201);
47} catch (error) {
48return c.json({ success: false, error: "Failed to create task" } as ApiResponse<never>, 500);
49}
50});
55const id = parseInt(c.req.param("id"));
56if (isNaN(id)) {
57return c.json({ success: false, error: "Invalid task ID" } as ApiResponse<never>, 400);
58}
59
61
62if (body.title !== undefined && body.title.trim().length === 0) {
63return c.json({ success: false, error: "Task title cannot be empty" } as ApiResponse<never>, 400);
64}
65
66const updatedTask = await updateTask(id, body);
67if (!updatedTask) {
68return c.json({ success: false, error: "Task not found" } as ApiResponse<never>, 404);
69}
70
71return c.json({ success: true, data: updatedTask } as ApiResponse<typeof updatedTask>);
72} catch (error) {
73return c.json({ success: false, error: "Failed to update task" } as ApiResponse<never>, 500);
74}
75});
80const id = parseInt(c.req.param("id"));
81if (isNaN(id)) {
82return c.json({ success: false, error: "Invalid task ID" } as ApiResponse<never>, 400);
83}
84
85const deleted = await deleteTask(id);
86if (!deleted) {
87return c.json({ success: false, error: "Task not found" } as ApiResponse<never>, 404);
88}
89
90return c.json({ success: true, data: { deleted: true } } as ApiResponse<{ deleted: boolean }>);
91} catch (error) {
92return c.json({ success: false, error: "Failed to delete task" } as ApiResponse<never>, 500);
93}
94});
untitled-6073types.ts1 match
18}
1920export interface ApiResponse<T> {
21success: boolean;
22data?: T;
untitled-6073README.md7 matches
15```
16โโโ backend/
17โ โโโ index.ts # Main Hono API server
18โ โโโ database/
19โ โ โโโ migrations.ts # Database schema
32```
3334## API Endpoints
3536- `GET /api/tasks` - Get all tasks
37- `POST /api/tasks` - Create a new task
38- `PUT /api/tasks/:id` - Update a task
39- `DELETE /api/tasks/:id` - Delete a task
4041## Tech Stack
4243- **Backend**: Hono (API framework)
44- **Database**: SQLite
45- **Frontend**: React with TypeScript
2223// Generate poem endpoint
24app.post("/api/generate-poem", async c => {
25try {
26const request: PoemRequest = await c.req.json();
ffffindex.html1 match
8<script src="https://esm.town/v/std/catch"></script>
9<link rel="stylesheet" href="/frontend/style.css">
10<link href="https://fonts.googleapis.com/css2?family=Crimson+Text:ital,wght@0,400;0,600;1,400&family=Inter:wght@300;400;500&display=swap" rel="stylesheet">
11</head>
12<body>