import { serve } from "@hono/node-server"; import { createApp } from "./app"; import { loadEnv } from "./env"; const env = loadEnv(); const lifecycle = process.env.npm_lifecycle_event ?? ""; const serveUi = env.isProduction || lifecycle === "start"; const app = await createApp({ ...env, isProduction: serveUi }); const port = serveUi ? env.port : env.apiPort; try { serve({ fetch: app.fetch, port, hostname: "127.0.0.1" }, () => { console.log( `Listening on http://127.0.0.1:${port}${serveUi ? " (app + api)" : " (api)"}`, ); }); } catch (err) { console.error(err); process.exit(1); } process.on("uncaughtException", (err: NodeJS.ErrnoException) => { if (err.code === "EADDRINUSE") { console.error( `Port ${port} is already in use. Stop the other npm run dev / node process, then start again.`, ); process.exit(1); } throw err; });