compose - options related to the composition of server, plugin, and the returned plugin instance.

compose.server - hapi server options. These options will be used to create the root server for plugin to live on. Note that this cannot be set when server is passed but compose.controlled is false: in that case plugin is registered directly to server, and an additional hapi server will not be created.

compose.register - additional plugins to register to the same server as plugin, usually to fulfill plugin's dependencies. This may take the shape { plugins, options } or just plugins, where plugins and options are defined as the arguments to server.register(plugins, [options]).

compose.controlled - when a server is specified but this is set to false, plugin will be registered directly to server. By default plugin will be instanced on a separate server, but controlled by server, meaning that it's tied to server's initialize/start/stop lifecycle.

compose.initialize - may be set to true or false to determine whether to initialize the plugin instance. In a controlled situation (per compose.controlled) this option defaults to false; when set to true, server will be initialized (in turn the plugin instance is also intialized). In a non-controlled situation this option defaults to true; when set to false, the returned plugin instance will not be initialized.

compose.decorateRoot - determines whether or not the returned plugin instance should have a rootdecoration that references the root server to which it is registered. Defaults to true unless server is specified but compose.controlled is false.

compose.decorateController - determines whether or not the returned plugin instance should have a controllerdecoration that references the controlling server. Defaults to true when in a controlled situation (per compose.controlled).

Example

// index.jsconstHapi=require('@hapi/hapi');constMyPlugin=require('./my-plugin');(async()=>{// Your plugin can be used without explicitly utilizing hapi or ahem:constapp=awaitMyPlugin.create({/* options */});// Or it can be registered normally as a hapi plugin:constserver=Hapi.server();awaitserver.register({plugin: MyPlugin,options: {/* options */}});})();

Example

// npm install ahem @hapi/hapiconstHapi=require('@hapi/hapi');constAhem=require('ahem');constApp=require('./app');(async()=>{constserver=Hapi.server();awaitserver.register(Ahem);constapp=awaitserver.instance(App);// app is not yet initializedawaitserver.initialize();// app is now initialized tooawaitserver.stop();// app is now stopped too})();

Glossary

Plugin-server

// This is a hapi pluginexports.plugin={name: 'my-plugin',register(server,options){// ^^^^^^ This is a plugin-server}};

If you've written a hapi plugin then you're already familiar with this idea, although you might not have a name for it. Every hapi plugin defines a register() function: async register(server, options). The server passed to this function by hapi is what we call the "plugin-server." It is different from the server returned by Hapi.server(), sometimes called the "root server", because plugin-servers are scoped to a realm created by hapi specific to the registration of that plugin.