Skip to main content

Custom Middlewares

A middleware is an object that should contain at least 1 of 3 possible keys:

  1. before: a function that is executed in the before phase
  2. after: a function that is executed in the after phase
  3. onError: a function that is executed in case of errors

before, after and onError functions need to have the following signature:

async (request) => {
// ...
}

Where:

  • request: is a reference to the current context and allows access to (and modification of) the current event (request), the response (in the after phase), and error (in case of an error).