让Hapi仅注册一次@ Hapi/Good插件 [英] Get Hapi to Register @Hapi/Good Plugin Only Once
问题描述
Hapi(v17& 18)指出,我可以在server.register
上指定一个选项,以使该插件一次初始化一次,而不管该插件调用server.register
的次数如何-
Hapi (v17 & 18) states that I can specify an option on server.register
to make the plugin on get initialized once, regardless of however many times server.register
is called with that plugin - link to docs. However, I have been unable to get this to work.
我尝试将options元素放在传递给server.register
的对象上.当我尝试运行服务器时,出现错误[1] "once" conflict with forbidden peer "options"
.这使我相信它必须放在options
对象中.
I have tried putting options an element on the object that gets passed into server.register
. When I try to run the server, I get the error [1] "once" conflict with forbidden peer "options"
. This leads me to believe that it must go in the options
object.
await server.register({
plugin: require('@hapi/good'),
options: { /* omitted */ },
once: true
});
我尝试将其添加到传递到server.register
的选项对象中.但是,出现此错误[1] "once" is not allowed
.
I try to add it to the options object that gets passed into server.register
. However, I get this error [1] "once" is not allowed
.
await server.register({
plugin: require('@hapi/good'),
options: {
once: true,
/* omitted */
},
});
除了这个 github问题.但是,这仅涵盖了routes
.
I have not been able to find an example of this option anywhere online besides this github issue. However, that only covers the routes
.
推荐答案
@hapi/good
使用Joi检查可以将哪些有效选项传递给插件.请在源代码中此处中进行阅读.似乎@hapi/good
禁止使用routes
和once
,因为默认情况下它拒绝除允许的实体之外的所有实体.不过,这似乎是一个问题,因为once
是服务器的插件配置,而不是插件的配置.
@hapi/good
uses Joi to check what valid options can be passed in to the plugin. Check be read here in the source code. It seems that @hapi/good
prohibits the use of routes
and once
because it denies all except the allowed entities by default. This seems to be an issue though because once
is a configuration of the plugin for the server - not for the plugin.
这篇关于让Hapi仅注册一次@ Hapi/Good插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!