import { serve } from '@hono/node-server'; import { serveStatic } from '@hono/node-server/serve-static'; import fs from 'node:fs'; import path from 'node:path'; import { createApp } from './app.js'; import { openDb } from './db.js'; const db = openDb(process.env.DB_PATH ?? 'data/billing.db'); const app = createApp(db); // In production the built web app is served from the same origin. const webDir = process.env.WEB_DIR; if (webDir) { const index = fs.readFileSync(path.join(webDir, 'index.html'), 'utf8'); app.use('/*', serveStatic({ root: path.relative(process.cwd(), webDir) })); app.get('*', (c) => (c.req.path.startsWith('/api/') ? c.notFound() : c.html(index))); } const port = Number(process.env.PORT ?? 3000); serve({ fetch: app.fetch, port }, () => console.log(`billing server on :${port}`));