import { createRouter } from './create-router'; import { openaiError } from './errors'; import type { HonoVariables } from './create-router'; import type { Hono } from 'hono'; import { imagesRouter } from './api/images'; import { providersRouter } from './api/providers'; import { collectionsRouter } from './api/collections'; import { filesRouter } from './api/files'; /** * Every router this sidecar answers, and the prefix it answers on. * * Bare — no `/api` prefix of its own. `createSidecarProxy` (../api/router.ts, on the platform side) * already strips `/api/atelier` before forwarding, so what arrives here is exactly the subpath: a * request for `/api/atelier/images/generations` arrives as `/images/generations`. * * `ping` and `echo` from the standalone service are not here — they were smoke-test routes with no * caller; the sidecar's own `/_health` (see index.ts) covers liveness instead. */ const MOUNTS: [string, Hono<{ Variables: HonoVariables }>][] = [ ['/images', imagesRouter], ['/providers', providersRouter], ['/collections', collectionsRouter], ['/files', filesRouter], ]; export function buildHonoApp() { const app = createRouter(); for (const [prefix, router] of MOUNTS) app.route(prefix, router); app.notFound((ctx) => ctx.json(openaiError('Not found', 'not_found'), 404)); app.onError((error, ctx) => { console.error('[atelier]', error); return ctx.json(openaiError('Internal Server Error', 'server_error'), 500); }); return app; }