Skip to content

SudoSOS Back-end API / internal/middleware / RequestContextMiddleware

Class: RequestContextMiddleware ​

This class is responsible for binding a RequestContext to every request, so that log lines can be correlated per request. It should be registered before any router, as requests that are rejected by other middleware are the ones that benefit the most from being correlatable.

Constructors ​

Constructor ​

ts
new RequestContextMiddleware(): RequestContextMiddleware;

Returns ​

RequestContextMiddleware

Methods ​

getMiddleware() ​

ts
getMiddleware(): RequestHandler;

Returns ​

RequestHandler

a middleware handler to be used by express.


handle() ​

ts
handle(
   req, 
   res, 
   next
): void;

Middleware handler that binds a request context to the remainder of the request.

Parameters ​

ParameterTypeDescription
reqRequestthe express request to handle.
resResponsethe express response object.
nextFunctionthe express next function to continue processing of the request.

Returns ​

void