Skip to Content

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(): RequestHandler

Usage 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

StepWhat happens
Request has x-socket-idAttaches per-request inspector metadata on req (socketId, correlationId, source: 'http')
No headerMiddleware calls next() — normal HTTP clients are unaffected
Handler runsregisterCatPipeline 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

RequirementNotes
createInspectorCorrelationMiddleware() on /api (or your HTTP prefix)Required for live trace
registerCatPipeline + cat() / @CatRequired for ApiReturn labels
attachCatRPCCatalog, RPC steps, receiving broadcasts
CORS allows X-Socket-IdBrowser fetch from frontend origin

See also