/** * {{APP_NAME}} — server component entry point. * * Order matters here. We run `deploy()` to completion BEFORE starting the * HTTP server so the schema is current before we accept traffic. Migrations * are fatal: if they throw, the process crashes rather than serving against * a half-migrated database. Sync rules push is non-fatal — see deploy.ts. * * `await` at the top level requires `"type": "module"` in package.json * (Bun and Node both support this). The platform supervisor restarts the * process if `deploy()` throws. */ import { deploy } from './deploy'; import { routes } from './routes'; // PORT and HOST come from the platform when running under `kazzle run`. // The fallback (3001 / 127.0.0.1) is only for direct `bun run index.ts` // invocations during local hacking. // ───────────────────────────────────────────────────────────────────────── // DO NOT CHANGE THE NEXT 4 LINES. DO NOT ADD FALLBACKS. DO NOT HARDCODE. // PORT and HOST are injected by `kazzle run`. Missing values must throw so // the platform sees a fast, readable failure instead of binding to the // wrong port. // ───────────────────────────────────────────────────────────────────────── if (!process.env.PORT || !process.env.HOST) { throw new Error('PORT and HOST must be set by "kazzle run" — never hardcode them.'); } const PORT = Number(process.env.PORT); const HOST = process.env.HOST; await deploy(); const server = Bun.serve({ hostname: HOST, port: PORT, fetch: routes, }); console.log(`[{{APP_NAME}}] Server listening on ${server.hostname}:${server.port}`);