Merge branch 'fix/dev-routes-on-fetch' into develop
CI / build (push) Has been cancelled

Serve /__graph__ + /__openapi__ over app.fetch so the dev tools (graph viewer,
OpenAPI) work on Deno/Bun/edge, not just the Node listen() path.
This commit is contained in:
chrnx committed 2026-07-10 00:10:56 -05:00
commit e54de8c1db
3 files changed
+42 -4

No files matched your search

+5
View File
@@ -16,6 +16,11 @@ green-tea uses calendar versioning: `YY.MM.PATCH`.
- **Cloudflare Workers / edge adapter** (`@green-tea/core/edge`): `edgeHandler(app)` runs HTTP + SSE + WebSocket on workerd, reusing the neutral `app.upgrade` / `WsSocket` capability. Requires the `nodejs_compat` compatibility flag. Green Tea now runs on Node, Deno, Bun, and the edge — with identical WebSocket, rooms, and channel behaviour on all four.
- **`app.upgrade(request, socket)`**: neutral WebSocket entry point for non-Node runtimes, built on a shared `WsSocket` capability. WebSocket logic is now runtime-agnostic (`src/http/ws-core.ts`).
### Fixed
- The opt-in dev routes `/__graph__` (graph viewer) and `/__openapi__` are now
served over `app.fetch` too, so they work on every runtime (Deno/Bun/edge),
not only the Node `app.listen()` path.
### Changed
- App-scope providers now boot exactly once (memoized): a second `app.listen()`
call no longer re-runs provider factories or their side effects.
+13 -4
View File
@@ -119,6 +119,15 @@ export function createApp(opts: {
info,
);
// Dev-only introspection routes (opt-in). Shared by BOTH listen() and app.fetch so the
// graph viewer + OpenAPI doc are served on every runtime (Node/Deno/Bun/edge), not Node alone.
const devRoutes = (): RouteDef[] => {
const routes: RouteDef[] = [];
if (opts.devGraph) routes.push(devGraphRoute(graph));
if (opts.devOpenapi) routes.push(openApiRoute(openapi));
return routes;
};
const providedSeed = (plan: RoutePlan) => seedProviders(container, plan);
const planSteps = (plan: RoutePlan) => compilePlanSteps(runners, plan);
@@ -147,6 +156,7 @@ export function createApp(opts: {
{ providedSeed, planSteps, bus, onError: opts.onError },
fetchOpts,
bootAppProviders,
devRoutes,
);
const upgradeFn = buildAppUpgrade(
() => booted,
@@ -179,9 +189,7 @@ export function createApp(opts: {
deps,
});
const httpRoutes = buildHttpRoutes(routePlans, remoteRoutes, deps);
if (opts.devGraph) httpRoutes.push(devGraphRoute(graph));
if (opts.devOpenapi) httpRoutes.push(openApiRoute(openapi));
const httpRoutes = [...buildHttpRoutes(routePlans, remoteRoutes, deps), ...devRoutes()];
const wsRoutes = buildWsRoutes(routePlans, deps);
server = createHttpServer(httpRoutes, wsRoutes, bus, meshControl, {
@@ -638,13 +646,14 @@ function buildAppFetch(
deps: PipelineDeps,
fetchOpts: HttpOptions,
ensureBooted: () => Promise<void>,
devRoutes: () => RouteDef[],
): (request: Request) => Promise<Response> {
let handler: ((request: Request) => Promise<Response>) | undefined;
return async (request: Request): Promise<Response> => {
if (!handler) {
if (!getBooted()) throw new Error('fetch() unavailable before listen() for mesh apps');
handler = buildFetch(buildHttpRoutes(routePlans, [], deps), fetchOpts);
handler = buildFetch([...buildHttpRoutes(routePlans, [], deps), ...devRoutes()], fetchOpts);
}
await ensureBooted(); // idempotent: no-op if listen() already booted the providers
+24
View File
@@ -398,6 +398,30 @@ describe('devGraph endpoint', () => {
expect(res.status).toBe(404);
s.close();
});
it('serves /__graph__ and /__openapi__ over app.fetch too (runtime-agnostic dev tools)', async () => {
@Route('/u')
class Ctl {
@Get('/me') me() {
return { ok: 1 };
}
}
@Module({ mountpoint: '/api', controllers: [Ctl] })
class M {}
const app = createApp({ modules: [M], devGraph: true, devOpenapi: true });
const graph = await app.fetch(new Request('http://x/__graph__'));
expect(graph.status).toBe(200);
expect(await graph.text()).toContain('cytoscape');
const openapi = await app.fetch(new Request('http://x/__openapi__'));
expect(openapi.status).toBe(200);
expect(((await openapi.json()) as { openapi: string }).openapi).toBe('3.1.0');
// still absent when the flags are off, on the fetch path too
const off = createApp({ modules: [M] });
expect((await off.fetch(new Request('http://x/__graph__'))).status).toBe(404);
});
});
describe('graceful shutdown', () => {