(plugins, options = {})
| 408 | } |
| 409 | |
| 410 | async register(plugins, options = {}) { |
| 411 | |
| 412 | if (this.realm.modifiers.route.prefix || |
| 413 | this.realm.modifiers.route.vhost) { |
| 414 | |
| 415 | options = Hoek.clone(options); |
| 416 | options.routes = options.routes ?? {}; |
| 417 | |
| 418 | options.routes.prefix = (this.realm.modifiers.route.prefix ?? '') + (options.routes.prefix ?? '') || undefined; |
| 419 | options.routes.vhost = this.realm.modifiers.route.vhost ?? options.routes.vhost; |
| 420 | } |
| 421 | |
| 422 | options = Config.apply('register', options); |
| 423 | |
| 424 | ++this._core.registring; |
| 425 | |
| 426 | try { |
| 427 | const items = [].concat(plugins); |
| 428 | for (let item of items) { |
| 429 | |
| 430 | /* |
| 431 | { register, ...attributes } |
| 432 | { plugin: { register, ...attributes }, options, once, routes } |
| 433 | { plugin: { plugin: { register, ...attributes } }, options, once, routes } // Required module |
| 434 | */ |
| 435 | |
| 436 | if (!item.plugin) { |
| 437 | item = { |
| 438 | plugin: item |
| 439 | }; |
| 440 | } |
| 441 | else if (!item.plugin.register) { |
| 442 | item = { |
| 443 | options: item.options, |
| 444 | once: item.once, |
| 445 | routes: item.routes, |
| 446 | plugin: item.plugin.plugin |
| 447 | }; |
| 448 | } |
| 449 | else if (typeof item === 'function') { |
| 450 | item = Object.assign({}, item); // Shallow cloned |
| 451 | } |
| 452 | |
| 453 | item = Config.apply('plugin', item); |
| 454 | |
| 455 | const name = item.plugin.name ?? item.plugin.pkg.name; |
| 456 | const clone = this._clone(name); |
| 457 | |
| 458 | clone.realm.modifiers.route.prefix = item.routes.prefix ?? options.routes.prefix; |
| 459 | clone.realm.modifiers.route.vhost = item.routes.vhost ?? options.routes.vhost; |
| 460 | clone.realm.pluginOptions = item.options ?? {}; |
| 461 | |
| 462 | // Validate requirements |
| 463 | |
| 464 | const requirements = item.plugin.requirements; |
| 465 | Hoek.assert(!requirements.node || Config.versionMatch(process.version, requirements.node), 'Plugin', name, 'requires node version', requirements.node, 'but found', process.version); |
| 466 | Hoek.assert(!requirements.hapi || Config.versionMatch(this.version, requirements.hapi), 'Plugin', name, 'requires hapi version', requirements.hapi, 'but found', this.version); |
| 467 |
no test coverage detected