registerPlugins()
What?
Integrates standard Hapi.js plugins into the underlying server instance.
Why?
Plugins provide cross-cutting concerns like Swagger documentation, health checks, or specialized authentication schemes that operate at the Hapi.js lifecycle level.
How to use
public async initPlugins() {
await this.registerPlugins([
...DefaultPlugins,
SwaggerPlugin,
{
plugin: CustomHapiPlugin,
options: {
someSetting: true
}
}
]);
}
Under the Hood
- It delegates directly to Hapi's
server.register(). - It supports a specialized Archibald wrapper that allows
optionsto be a function, which is useful when options need to be dynamically computed based on theConfigService.