Get Hapi to Register @Hapi/Good Plugin Only Once

六眼飞鱼酱① 提交于 2019-12-13 03:19:38

问题


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.

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
  });

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 */
    },
  });

I have not been able to find an example of this option anywhere online besides this github issue. However, that only covers the routes.


回答1:


@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.



来源:https://stackoverflow.com/questions/57095818/get-hapi-to-register-hapi-good-plugin-only-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!