createInspectorCorrelationMiddleware
Express middleware that links each HTTP request to the QA inspector Socket.IO tab that triggered it. The frontend pipeline sends x-socket-id on HTTP scenario fetch steps; this middleware reads that header so live API_RESPONSE events from registerCatPipeline and ApiReturn appear on the correct tab.
Import from the Socket.IO entry (not the main package):
import { createInspectorCorrelationMiddleware } from '@gloocan/cat-inspector/socket-io'Also exported: INSPECTOR_SOCKET_ID_HEADER ('x-socket-id') from the main package — same header name the QA client uses.
Signature
function createInspectorCorrelationMiddleware(): RequestHandlerUsage on the server
Mount on the same path prefix as your instrumented routes, before routers that use registerCatPipeline:
import express from 'express'
import { createInspectorCorrelationMiddleware } from '@gloocan/cat-inspector/socket-io'
const app = express()
app.use(express.json())
app.use('/api', createInspectorCorrelationMiddleware()) // ← before registerCatPipeline routes
// app.use('/api', yourInstrumentedRouter)Typical stack with Socket.IO (same pattern as cat-demo):
import { attachCatRPC, createInspectorCorrelationMiddleware } from '@gloocan/cat-inspector/socket-io'
app.use(express.json())
app.use('/api', createInspectorCorrelationMiddleware())
app.use('/api', sdkShowcaseHttpRouter)
attachCatRPC(io, { scanRoots: [...], ... })CORS: allow X-Socket-Id (and your auth headers) on preflight, e.g. Access-Control-Allow-Headers: Content-Type, Authorization, X-Socket-Id.
Behavior
| Step | What happens |
|---|---|
Request has x-socket-id | Attaches per-request inspector metadata on req (socketId, correlationId, source: 'http') |
| No header | Middleware calls next() — normal HTTP clients are unaffected |
| Handler runs | registerCatPipeline reads that metadata and broadcasts API_RESPONSE / related events only to that socket |
The QA app adds X-Socket-Id automatically when the user is connected on the pipeline page. Without this middleware, HTTP handlers still run and status/body asserts still work, but the live HTTP trace panel may stay empty.
Pipeline checklist
| Requirement | Notes |
|---|---|
createInspectorCorrelationMiddleware() on /api (or your HTTP prefix) | Required for live trace |
registerCatPipeline + cat() / @Cat | Required for ApiReturn labels |
attachCatRPC | Catalog, RPC steps, receiving broadcasts |
CORS allows X-Socket-Id | Browser fetch from frontend origin |
See also
registerCatPipeline— instrumented Express routesApiReturn— response labels anderror/issuesbody conventions in the trace UI- Socket.IO transport —
attachCatRPC readInspectorSocketIdFromHeaders— custom adapters