api/src/index.node.ts
22 lines · 703 bytes
1// Bun/Node entry, serves the same app with env from process.env
2import { buildApp } from '@/app'
3import { readEnv } from '@/lib/env'
4import { log } from '@/lib/log'
5
6const app = buildApp()
7const env = readEnv()
8const port = Number(process.env.PORT ?? 8787)
9
10// Hand each incoming request the unified env as c.env
11const handler = (request: Request) => app.fetch(request, env)
12
13if (typeof Bun !== 'undefined') {
14 Bun.serve({ port, fetch: handler })
15 log.info('listening', { port, runtime: 'bun' })
16} else {
17 // Node fallback for non-Bun runtime
18 const { serve } = await import('@hono/node-server')
19 serve({ fetch: handler, port }, () => {
20 log.info('listening', { port, runtime: 'node' })
21 })
22}