Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.4 KB

File metadata and controls

43 lines (31 loc) · 1.4 KB

Fastify example (@arcp/fastify)

Same pattern as the Express example, but the HTTP side is Fastify so you also see its structured pino logger and per-request req.id.

attachArcpToFastify(app, { path, allowedHosts, onTransport }) mounts the WS upgrade handler on the app.server (the Node http.Server Fastify created). Fastify's request pipeline is never consulted for the upgrade — Node's http.Server emits upgrade before any Fastify route runs.

Run

In one terminal:

pnpm tsx examples/fastify/server.ts

In a second terminal:

pnpm tsx examples/fastify/client.ts

The client makes GET /health (the response includes Fastify's req_id, generated by genReqId), then opens an ARCP WebSocket on the same port and submits an echo job. Stop the server with Ctrl+C.

What it demonstrates

  • One Node HTTP server, two protocols on one port (Fastify HTTP + ARCP).
  • Fastify's structured pino logger writing alongside ARCP's own logs.
  • Fastify-style per-request id propagated to the /health body.
  • DNS-rebinding protection via allowedHosts on the upgrade.

Configuration

Env var Default Used by
ARCP_DEMO_PORT 7897 both
ARCP_DEMO_URL ws://127.0.0.1:7897/arcp client
ARCP_DEMO_TOKEN demo-token both