Support plan
- which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community
- is this issue currently blocking your project? (yes/no): No
- is this issue affecting a production system? (yes/no): No
Context
- node version: 12 LTS
- module version: 19.1.1
- environment (e.g. node, browser, native): node
- used with (e.g. hapi application, another framework, standalone, ...): hapi application
- any other relevant information: none
What problem are you trying to solve?
When authoring a plugin that can be configured "per route", it is often necessary to validate those options (ideally at boot time) so that no incorrect configuration is provided to the plugin.
server.route({
method: 'GET',
path: '/',
options: {
plugins: {
pluginNS: {} // validate these options are correct at boot time
}
}
});
It is possible to manually perform this validation, but ideally a more declarative approach can be used.
Validating at boot time:
server.ext('onPreStart', () => {
// Prepare plugin options
const routes = server.table();
for (const route of routes) {
if ('pluginNS' in route.settings.plugins) {
route.settings.plugins.pluginNS = Joi.attempt(route.settings.plugins.pluginNS, schema);
}
}
});
Reference: https://github.com/kanongil/nipo/blob/master/lib/index.js#L404-L414
Validating at runtime:
options = Joi.attempt(request.route.settings.plugins.pluginNS, schema);
Reference: https://github.com/nlf/blankie/blob/master/lib/index.js#L271
Do you have a new or modified API suggestion to solve the problem?
I don't have a particular approach or design in mind. Any help here would be appreciated.
Support plan
Context
What problem are you trying to solve?
When authoring a plugin that can be configured "per route", it is often necessary to validate those options (ideally at boot time) so that no incorrect configuration is provided to the plugin.
It is possible to manually perform this validation, but ideally a more declarative approach can be used.
Validating at boot time:
Reference: https://github.com/kanongil/nipo/blob/master/lib/index.js#L404-L414
Validating at runtime:
Reference: https://github.com/nlf/blankie/blob/master/lib/index.js#L271
Do you have a new or modified API suggestion to solve the problem?
I don't have a particular approach or design in mind. Any help here would be appreciated.