seahaven-ap/packages/api/src/app.ts
Adam Moussa 9d3646876e
feat(api): stand up Hono Drizzle foundation with auth and Redocly (AP-14) (#12)
* feat(api): stand up Hono Drizzle foundation with auth and Redocly

* fix(api): bump drizzle-orm and hono node-server past audit highs

* fix(api): harden auth upsert and Cognito token verification
2026-08-11 00:10:49 +00:00

28 lines
861 B
TypeScript

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<AppBindings>();
const auth = createAuthMiddleware(env, handle);
app.route("/", createHealthRoutes(handle));
const api = new Hono<AppBindings>();
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<typeof createApp>;