mirror of
https://github.com/Sea-Haven-Industries/seahaven-ap.git
synced 2026-10-01 17:53:18 +00:00
* 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
28 lines
861 B
TypeScript
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>;
|