Skip to content

feat(server): serve the Express app through a Fastify 5 shell - #129

Merged
YvigUnderscore merged 1 commit into
devfrom
feat/fastify-shell
Dec 4, 2026
Merged

YvigUnderscore merged 1 commit into
devfrom
feat/fastify-shell

Conversation

@YvigUnderscore

Copy link
Copy Markdown
Owner

What

Phase 2a step 2 (logs/phase-2a/plan-2a.md): Fastify 5 becomes the HTTP front door, with the whole V2 Express app mounted inside it through @fastify/express. No route moves yet.

  • apps/server/src/http/fastify-shell.ts: builds the shell around an Express app.
  • createApp() is async and returns the shell as a Node request listener; buildExpressApp() is the Express app alone. server.ts, unit and integration callers await it.
  • Dependencies: fastify 5.12.8, @fastify/express 4.0.14 (+ socket.io-client dev, for the integration check); notices regenerated.

Why

Approved on 1 Dec (probes/fastify/REPORT.md): Fastify 5 replaces Express 5 by mounting V2 inside it. The probe's conditions for this step: its two shell fixes and their tests from day one. One code path, no HTTP_SHELL switch (agent call in the plan, accepted with it).

The two fixes (probe findings 1 and 2)

  • Hang: Express parses bodies; when it finds no route it hands the request to Fastify, whose parser would wait for a body already consumed. Fastify now accepts every content type without reading it while Express owns parsing.
  • Client IP behind nginx: @fastify/express replaces req.ip with Fastify's. Fastify gets Express's compiled trust function (a bare hop count gave the proxy's address, and Fastify 5 now refuses a number). Hop-based like V2; safe because nginx is the only service publishing a port.

Both tests fail when their fix is removed (checked by reverting each fix locally).

Known until step 3 (pinned by a test that step 3 flips)

Through the shell, Express routes lose their ETag (no 304) and the echoed x-request-id; an unknown path answers Fastify's JSON 404 instead of Express's HTML page. Security headers, CORS and error bodies are unchanged. Step 3 moves helmet/CORS, request id, error format and ETag to the Fastify side. Nothing reaches main before step 3.

How verified

  • pnpm validate: green.
  • Local CI (same jobs as GitHub): checks, backend (4415 unit, 208 integration incl. the 2 new), frontend, e2e (5/5) green.
  • Compiled server started: /health 200 with the Helmet headers, unknown path 404, /api/projects 401.

Risks

  • createApp() changed signature (async, returns a request listener): every caller in this repo updated; no other consumer.
  • Not exercised live: HLS pipe, file uploads through the shell (uploads use presigned S3 URLs, no bytes cross the server), Server-Sent Events, production nginx in front.

Migration notes

None (no schema, env or config change).

🤖 Generated with Claude Code

Phase 2a step 2. Fastify 5 is the HTTP front door; the whole V2 Express
app is mounted inside it with @fastify/express, so routes can leave
Express one group at a time. One code path: no switch back to Express
alone (rollback is reverting this change).

- `createApp()` is now async and returns the shell as a Node request
  listener; `buildExpressApp()` is the Express app on its own. Server,
  unit and integration callers await it.
- The transition probe's two fixes ship with their tests: Fastify never
  parses bodies while Express owns parsing (a body sent to an unknown
  route used to hang), and Fastify trusts exactly the proxies Express
  trusts, through Express's compiled trust function (the client IP
  behind nginx used to be the proxy's). Both tests fail when their fix
  is removed.
- Unit tests compare V2 alone and through the shell (public route and
  security headers, refused-call shape, 404, body limits, streaming and
  Range); an integration test checks Socket.io on the shell's server
  and a signed webhook raw body.
- Known until step 3, pinned by a test: Express routes lose their ETag
  (no 304) and the echoed x-request-id through the shell, and an
  unknown path answers Fastify's JSON 404 instead of Express's HTML.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@YvigUnderscore
YvigUnderscore merged commit efea619 into dev Dec 4, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant