2 Commits
Author SHA1 Message Date
chrnx e54de8c1db 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.
2026-07-10 00:10:56 -05:00
chrnx df13a62d93 fix(app): serve /__graph__ and /__openapi__ over app.fetch (dev tools on all runtimes)
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-07-10 00:10:54 -05:00
3 changed files with 42 additions and 4 deletions

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. - **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`). - **`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 ### Changed
- App-scope providers now boot exactly once (memoized): a second `app.listen()` - App-scope providers now boot exactly once (memoized): a second `app.listen()`
call no longer re-runs provider factories or their side effects. call no longer re-runs provider factories or their side effects.
+13 -4
View File
@@ -119,6 +119,15 @@ export function createApp(opts: {
info, 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 providedSeed = (plan: RoutePlan) => seedProviders(container, plan);
const planSteps = (plan: RoutePlan) => compilePlanSteps(runners, plan); const planSteps = (plan: RoutePlan) => compilePlanSteps(runners, plan);
@@ -147,6 +156,7 @@ export function createApp(opts: {
{ providedSeed, planSteps, bus, onError: opts.onError }, { providedSeed, planSteps, bus, onError: opts.onError },
fetchOpts, fetchOpts,
bootAppProviders, bootAppProviders,
devRoutes,
); );
const upgradeFn = buildAppUpgrade( const upgradeFn = buildAppUpgrade(
() => booted, () => booted,
@@ -179,9 +189,7 @@ export function createApp(opts: {
deps, deps,
}); });
const httpRoutes = buildHttpRoutes(routePlans, remoteRoutes, deps); const httpRoutes = [...buildHttpRoutes(routePlans, remoteRoutes, deps), ...devRoutes()];
if (opts.devGraph) httpRoutes.push(devGraphRoute(graph));
if (opts.devOpenapi) httpRoutes.push(openApiRoute(openapi));
const wsRoutes = buildWsRoutes(routePlans, deps); const wsRoutes = buildWsRoutes(routePlans, deps);
server = createHttpServer(httpRoutes, wsRoutes, bus, meshControl, { server = createHttpServer(httpRoutes, wsRoutes, bus, meshControl, {
@@ -638,13 +646,14 @@ function buildAppFetch(
deps: PipelineDeps, deps: PipelineDeps,
fetchOpts: HttpOptions, fetchOpts: HttpOptions,
ensureBooted: () => Promise<void>, ensureBooted: () => Promise<void>,
devRoutes: () => RouteDef[],
): (request: Request) => Promise<Response> { ): (request: Request) => Promise<Response> {
let handler: ((request: Request) => Promise<Response>) | undefined; let handler: ((request: Request) => Promise<Response>) | undefined;
return async (request: Request): Promise<Response> => { return async (request: Request): Promise<Response> => {
if (!handler) { if (!handler) {
if (!getBooted()) throw new Error('fetch() unavailable before listen() for mesh apps'); 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 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); expect(res.status).toBe(404);
s.close(); 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', () => { describe('graceful shutdown', () => {