hapijs / glue

Server composer for hapi.js
Other
245 stars 62 forks source link

No way of passing default route validator to glue #139

Closed chrift closed 4 years ago

chrift commented 4 years ago

Support plan

Context

What are you trying to achieve or the steps to reproduce?

Trying to create routes using a default route validator

  {
    method: 'POST',
    path: '/cookie-settings',
    options: {
      auth: false,
      validate: {
        payload: {
          usage: Joi.string().valid('true', 'false').required(),
          campaigns: Joi.string().valid('true', 'false').required(),
          settings: Joi.string().valid('true', 'false').required(),
          redirectLink: Joi.string().allow('').optional()
        },
        failAction: handler.cookieSettingsHandler.postFail
      }
    },
    handler: handler.cookieSettingsHandler.post
  }

What was the result you got?

Error: Cannot set uncompiled validation rules without configuring a validator Doesn't seem like there's a way to set a default validator to glue

What result did you expect?

Expect to be able to pass Glue to instantiate hapi with a default validator [This](https://hapi.dev/api/?v=19.1.1#server.validator()) example of using hapi directly shows setting the validator after the server has been created, but glue creates the server and tries to attach routes without the chance to specify the validator.

chrift commented 4 years ago

After some more digging I've found you can specify a validator at this path of your glue manifest: manifest.server.routes.validate.validator = Joi