seahaven-ap/packages/api/src/app.ts
Adam Moussa cc637e3732
feat(api): serve portal-shaped health and error envelope
Move liveness to GET /api/health { stage, sha } with a Node 24 image on 8080 so ALB probes and deploy verify do not need auth or a database ping.
2026-09-22 12:33:19 -04:00

28 lines
925 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";
import { errorJson } from "./http.js";
export function createApp(env: ApiEnv, handle: Db) {
const app = new Hono<AppBindings>();
const auth = createAuthMiddleware(env, handle);
const api = new Hono<AppBindings>();
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<typeof createApp>;