import { env } from "@haushaltsApp/env/server";
import { Hono } from "hono";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
import { websocket } from "hono/bun";
import { registerRoutes } from "./routes";

const app = new Hono();

app.use(logger());
app.use(
  "/*",
  cors({
    origin: env.CORS_ORIGIN,
    allowMethods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
    allowHeaders: ["Content-Type", "Authorization", "x-household-id"],
    credentials: true,
  }),
);

registerRoutes(app);

export default {
  fetch: app.fetch,
  websocket,
  hostname: '0.0.0.0',
  port: Number(process.env.PORT ?? 3000)
}; 
