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
.
@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 ofroutes
andonce
because it denies all except the allowed entities by default. This seems to be an issue though becauseonce
is a configuration of the plugin for the server - not for the plugin.