Hooks are a basic way for addons to extend behavior in the request-response pipeline, at the middleware layer.
The following hooks are supported:
beforeAuthentication - triggered before calling the authenticate() method on any transport layer.
beforeRequestHandling - triggered before calling the handleBulkEndpoint() or handleJsonApiEndpoint() methods on any transport layer.
A hook can be registered from the app object, which receives two parameters: the appInstance and a hash containing a variety of properties. For example:
app.hook('beforeAuthentication', async (appInstance: ApplicationInstanceInterface, parameters: Record<string, any>) => {
// Do your magic here.
});
app.hook('beforeRequestHandling', async (appInstance: ApplicationInstanceInterface, parameters: Record<string, any>) => {
// Do your magic here.
});
At the moment, parameters is comprised of:
headers - a collection of all the headers provided by the request.
connection - a legacy object used to obtain information about the client's connection.
socket - a built-in property of the http module, which refers to the underlying socket supporting the connection.
You can register as many hook functions as you need by calling app.hook for each hook function you define.
Hooks are a basic way for addons to extend behavior in the request-response pipeline, at the middleware layer.
The following hooks are supported:
beforeAuthentication
- triggered before calling theauthenticate()
method on any transport layer.beforeRequestHandling
- triggered before calling thehandleBulkEndpoint()
orhandleJsonApiEndpoint()
methods on any transport layer.A hook can be registered from the
app
object, which receives two parameters: theappInstance
and a hash containing a variety of properties. For example:At the moment,
parameters
is comprised of:headers
- a collection of all the headers provided by the request.connection
- a legacy object used to obtain information about the client's connection.socket
- a built-in property of thehttp
module, which refers to the underlying socket supporting the connection.You can register as many hook functions as you need by calling
app.hook
for each hook function you define.