import { Hono } from "hono"; import type { ApiEnv } from "./env.js"; import type { Db } from "./db/client.js"; import { createAuthMiddleware, type AppBindings } from "./auth/middleware.js"; import { createHealthRoutes } from "./routes/health.js"; import { createMeRoutes } from "./routes/me.js"; export function createApp(env: ApiEnv, handle: Db) { const app = new Hono(); const auth = createAuthMiddleware(env, handle); app.route("/", createHealthRoutes(handle)); const api = new Hono(); api.use("*", auth); api.route("/", createMeRoutes()); app.route("/api", api); app.notFound((c) => c.json({ error: "Not found." }, 404)); app.onError((error, c) => { console.error(error); return c.json({ error: "Internal server error." }, 500); }); return app; } export type App = ReturnType;