Lifecycle and Hooks
Lifecycle in Frourio
Both frourio and frourio-express provide Hooks that take a form similar to fastify.
The overall lifecycle is shown in the figure below, and hooks such as onRequest
, preParsing
, preValidation
, and preHandler
can be defined.
Ref. Lifecycle - Fastify
The definition of Hooks can be found on the Routing page. See the following links for a reference on defineController()
and defineHooks()
.
Object ServerHooks
{
[(Hooks Name)]: HooksHandler or HooksHandler[],
}
An object whose keys are the same as the names of hooks and whose values are HooksHandler
or HooksHandler[]
.
Available names of hooks:
onRequest
preParsing
preValidation
preHandler
Function HooksHandler
- Fastify
- Express
Argument Type
request
:FastifyRequest
&AdditinalRequest
reply
:FastifyReply
done
: function<TError extends Error = FastifyError>(err?: TError) => void
done
is the function to continue with the lifecycle.
The done
callback is not available when using async
/await
or returning a Promise
. If you do invoke a done callback in this situation unexpected behavior may occur, e.g. duplicate invocation of handlers.
ref. Hooks - Fastify
Argument Type
req
:Request
&AdditinalRequest
res
:Response
next
: function(err?: any) => void
next
is the function to continue with the lifecycle including when using async
/await
or returning a Promise
.