Adding new behaviors to routes
At the beginning of this chapter, we learned how to use the routeOptions object to configure a route, but we did not talk about the config option!
This simple field gives us the power to do the following:
- Access the config in the handler and hook functions
- Implement the Aspect-Oriented Programming (AOP) that we are going to see later
How does it work in practice? Let’s find out!
Accessing the route’s configuration
With the routerOption.config parameter, you can specify a JSON that contains whatever you need. Then, it is possible to access it later within the Request component in the handlers or hooks’ function through the context.config field:
async function operation (request, reply) {
  return request.context.config
}
app.get('/', {
  handler: operation,
  config: {
    hello: 'world'
  }
})
In this way, you can create...