getOptionalMiddleware<T> function

Middleware<T> getOptionalMiddleware<T>(
  1. dynamic condition,
  2. Middleware<T> optionalMiddleware
)

Conditionally runs optional middleware or skips middleware

Example:

getOptionalMiddleware(
  (context, next) => context.user.isAdmin,
  addFieldsForAdmin
);

Implementation

Middleware<T> getOptionalMiddleware<T>(
  condition,
  Middleware<T> optionalMiddleware,
) {
  branchMiddlewareCondition<T>(condition);
  return getBranchMiddleware(condition, optionalMiddleware, skipMiddleware);
}