mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-05 09:28:08 +00:00
## Summary Extracts all studio API routes into a shared Hono-based module at `@hyperframes/core/studio-api`. ### Architecture - **`StudioApiAdapter` interface** — consumers inject host-specific behavior (project resolution, bundling, rendering, thumbnails) - **Shared route modules**: projects, files, preview, lint, render, thumbnail - **Shared helpers**: `isSafePath`, `walkDir`, `getMimeType`, `buildSubCompositionHtml` ### What this PR does - Creates the shared module with all API routes extracted from both `vite.config.ts` and `studioServer.ts` - Both consumers will be refactored in follow-up commits to mount this module with their own adapter ### What stays in each consumer - **Vite**: SSR module loading, Puppeteer thumbnails, file watcher + HMR, producer HTTP proxy, multi-project scanning - **CLI**: in-process `executeRenderJob`, local runtime serving, browser management, SPA static file serving ### Follow-up needed - [ ] Refactor `packages/studio/vite.config.ts` to use `createStudioApi(adapter)` via `@hono/node-server`'s `getRequestListener` - [ ] Refactor `packages/cli/src/server/studioServer.ts` to use `createStudioApi(adapter)` - [ ] Add `./studio-api` export path to `packages/core/package.json` - [ ] Add `hono` as peer dependency of `@hyperframes/core` ## Test plan - [ ] Verify shared module compiles without type errors - [ ] After consumer refactoring: all studio features work identically via both vite dev and CLI embedded servers 🤖 Generated with [Claude Code](https://claude.com/claude-code)
28 lines
987 B
TypeScript
28 lines
987 B
TypeScript
import { Hono } from "hono";
|
|
import type { StudioApiAdapter } from "./types.js";
|
|
import { registerProjectRoutes } from "./routes/projects.js";
|
|
import { registerFileRoutes } from "./routes/files.js";
|
|
import { registerPreviewRoutes } from "./routes/preview.js";
|
|
import { registerLintRoutes } from "./routes/lint.js";
|
|
import { registerRenderRoutes } from "./routes/render.js";
|
|
import { registerThumbnailRoutes } from "./routes/thumbnail.js";
|
|
|
|
/**
|
|
* Create a Hono sub-app with all studio API routes.
|
|
*
|
|
* Both the vite dev server and CLI embedded server mount this app
|
|
* under /api, each providing their own adapter for host-specific behavior.
|
|
*/
|
|
export function createStudioApi(adapter: StudioApiAdapter): Hono {
|
|
const api = new Hono();
|
|
|
|
registerProjectRoutes(api, adapter);
|
|
registerFileRoutes(api, adapter);
|
|
registerPreviewRoutes(api, adapter);
|
|
registerLintRoutes(api, adapter);
|
|
registerRenderRoutes(api, adapter);
|
|
registerThumbnailRoutes(api, adapter);
|
|
|
|
return api;
|
|
}
|