TypeScript/Bun project scaffold
- Stack: Bun, Hono, Drizzle ORM, Zod, Handlebars, Pino - Models: ticket, queue, transaction, scrip, template, custom_field, user, lifecycle - Scrip engine: prepare/commit two-phase dispatch, template rendering, mock actions - Lifecycle validator: state machine transition validation with wildcard support - Routes: health, tickets (full CRUD + preview + transactions), queues, scrips, custom-fields, lifecycles - Middleware: Pino logging, error handler - Database: Drizzle ORM schema + initial migration (10 tables) - Type-check: passes (tsc --noEmit, zero errors)
This commit is contained in:
46
src/index.ts
Normal file
46
src/index.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Hono } from 'hono';
|
||||
import { config } from './config.ts';
|
||||
import { createDb } from './db/index.ts';
|
||||
import type { Db } from './db/index.ts';
|
||||
import { errorHandler } from './middleware/error.ts';
|
||||
import { requestLogger } from './middleware/logging.ts';
|
||||
import healthRouter from './routes/health.ts';
|
||||
import { createTicketsRouter } from './routes/tickets.ts';
|
||||
import { createQueuesRouter } from './routes/queues.ts';
|
||||
import { createScripsRouter } from './routes/scrips.ts';
|
||||
import { createCustomFieldsRouter } from './routes/custom-fields.ts';
|
||||
import { createLifecyclesRouter } from './routes/lifecycles.ts';
|
||||
|
||||
let db: Db | null = null;
|
||||
|
||||
function getDb(): Db {
|
||||
if (!db) {
|
||||
db = createDb(config.DATABASE_URL);
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
app.use('*', requestLogger);
|
||||
app.onError(errorHandler);
|
||||
|
||||
app.route('/health', healthRouter);
|
||||
app.route('/tickets', createTicketsRouter(getDb()));
|
||||
app.route('/queues', createQueuesRouter(getDb()));
|
||||
app.route('/scrips', createScripsRouter(getDb()));
|
||||
app.route('/custom-fields', createCustomFieldsRouter(getDb()));
|
||||
app.route('/lifecycles', createLifecyclesRouter(getDb()));
|
||||
|
||||
export default app;
|
||||
export { app };
|
||||
|
||||
// Start server when run directly
|
||||
if (Bun.main === import.meta.path) {
|
||||
Bun.serve({
|
||||
fetch: app.fetch,
|
||||
port: config.SERVER_PORT,
|
||||
hostname: config.SERVER_HOST,
|
||||
});
|
||||
console.log(`Server running at http://${config.SERVER_HOST}:${config.SERVER_PORT}`);
|
||||
}
|
||||
Reference in New Issue
Block a user