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"; import { errorJson } from "./http.js"; export function createApp(env: ApiEnv, handle: Db) { const app = new Hono(); const auth = createAuthMiddleware(env, handle); const api = new Hono(); api.route("/", createHealthRoutes(env, handle)); api.use("*", auth); api.route("/", createMeRoutes()); app.route("/api", api); app.notFound((c) => errorJson(c, 404, "NOT_FOUND", "Not found.")); app.onError((error, c) => { console.error(error); return errorJson(c, 500, "INTERNAL_ERROR", "Internal server error."); }); return app; } export type App = ReturnType;