1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { cors } from "https://esm.sh/hono@3.11.7/middleware";
3import { runMigrations } from "./database/migrations.ts";
4import jobRoutes from "./routes/jobs.ts";
5import chatRoutes from "./routes/chat.ts";
18app.use("*", cors());
19
20// Run database migrations on startup
21app.use("*", async (c, next) => {
22 try {
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { getJobPostings, getChatMessages } from "../database/queries.ts";
4
5const static_routes = new Hono();
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { createChatMessage, getChatMessages } from "../database/queries.ts";
3
4const chat = new Hono();
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { createJobPosting, getJobPostings, getJobPostingById } from "../database/queries.ts";
3
4const jobs = new Hono();
6
7/**
8 * Run database migrations to set up the schema
9 */
10export async function runMigrations() {
31 `);
32
33 console.log("Database migrations completed");
34}
16
17- Backend: Hono.js API framework
18- Database: SQLite for data persistence
19- Frontend: HTML, JavaScript with Tailwind CSS
20- Data Refresh: Polling for chat updates
24```
25โโโ backend/
26โ โโโ database/
27โ โ โโโ migrations.ts # Schema definitions
28โ โ โโโ queries.ts # DB query functions
221. Set up a `CLAUDE_API_KEY` environment variable in Val Town with your Anthropic API key
232. Configure your Notion integration to send webhooks to this endpoint
243. Ensure your Notion database has the following properties:
25 - URL (URL type)
26 - Name (Title type)
271 // Try different possible locations for the URL in the Notion payload
272 if (payload.properties && payload.properties.URL && payload.properties.URL.url) {
273 // Database item with URL property
274 url = payload.properties.URL.url;
275 }
276 else if (payload.properties && payload.properties.URL && payload.properties.URL.rich_text &&
277 payload.properties.URL.rich_text.length > 0 && payload.properties.URL.rich_text[0].text) {
278 // Database item with URL in rich text
279 url = payload.properties.URL.rich_text[0].text.content;
280 }
6const LEAGUE_STANDINGS_TABLE = "chess_league_standings_1";
7
8export async function setupDatabase() {
9 // Create users table
10 await sqlite.execute(`
3import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4import { parseProject } from "https://esm.town/v/std/utils@85-main/index.ts";
5import { setupDatabase } from "./database/migrations.ts";
6import { getUsers, createUser, getUserById, updateUserStats } from "./database/queries.ts";
7import { createGame, getGame, updateGameState, getActiveGames, getUserGames } from "./database/game-queries.ts";
8import { getLeagueStandings, updateLeagueStandings } from "./database/league-queries.ts";
9
10// Initialize the Hono app
19app.use("/*", cors());
20
21// Setup database on startup
22app.use("*", async (c, next) => {
23 try {
24 await setupDatabase();
25 } catch (error) {
26 console.error("Database setup error:", error);
27 }
28 return next();