Custom Middlewares
A middleware is an object that should contain at least 1 of 3 possible keys:
before
: a function that is executed in the before phaseafter
: a function that is executed in the after phaseonError
: 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 currentevent
(request), theresponse
(in the after phase), anderror
(in case of an error).