import { Hono } from "hono"; import { cors } from "hono/cors"; import { logger } from "hono/logger"; import type { User, Session } from "@shared/types.js"; export type HonoContext = { Variables: { user?: User; session?: Session; }; }; export const createApp = () => { const app = new Hono(); app.use("*", logger()); app.use( "*", cors({ origin: (origin) => { if (process.env["NODE_ENV"] === "development") { return origin; } const allowedOrigins = process.env["ALLOWED_ORIGINS"]?.split(",") ?? []; return allowedOrigins.includes(origin) ? origin : allowedOrigins[0]; }, credentials: true, }) ); app.get("/health", (c) => { return c.json({ status: "healthy", timestamp: new Date().toISOString(), uptime: process.uptime(), }); }); return app; };