Route Integration
Routes are defined as a static configuration array. Instead of passing an anonymous function, Archibald uses a String Handler pattern to link a route to a controller method.
How to use
// Route Configuration
{
method: RouteMethod.GET,
path: '/users/address',
handler: 'AccountController.getAddress' // Links to the registered instance
}
Under the Hood: String Resolution
When registerRoute encounters a string handler, it performs the following logic:
- Parsing: Splits the string by
.to identify the controller key and the method name (e.g.,['AccountController', 'getAddress']). - Lookup: Retrieves the controller instance from the internal
controllersMap. - Binding: Wraps the method call in a Hapi handler and uses
.bind(controller). This is critical as it ensures thatthisinside the controller method correctly points to the controller instance, allowing access to its@Inject()ed services.