Files
billing/server/src/index.ts
T
dyc12389andClaude Opus 5.5 0b0aceb773 Family bookkeeping PWA modelled on 木木记账
Hono + SQLite server and a React/shadcn PWA with two-level categories,
who-spent/who-paid splits, settlement, one-line and voice entry, budget
alerts (Web Push and Bark), monthly/annual reports, and 木木 import tools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 12:05:39 +08:00

21 lines
814 B
TypeScript

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}`));