Closed KZTN closed 4 years ago
HEADERS does not contain "ong_id", but authorization. Remember that the request for headers must be performed within Joi.object() and not within .keys() Try this:
routes.post('/incidents', celebrate({
[Segments.HEADERS]: Joi.object({
authorization: Joi.string().required(),
}).unknown(),
[Segments.BODY]: Joi.object().keys({
title: Joi.string().required().max(35),
description: Joi.string().required().max(350),
value: Joi.number().required(),
}),
}), IncidentController.create)
HEADERS does not contain "ong_id", but authorization. Remember that the request for headers must be performed within Joi.object() and not within .keys() Try this:
routes.post('/incidents', celebrate({ [Segments.HEADERS]: Joi.object({ authorization: Joi.string().required(), }).unknown(), [Segments.BODY]: Joi.object().keys({ title: Joi.string().required().max(35), description: Joi.string().required().max(350), value: Joi.number().required(), }), }), IncidentController.create)
HI, thanks in advance. As said, it's ok about my HEADERS param. I'm just stuck with the BODY part. Celebrate just can't recognize my body params in this mode.
Are you using body-parser
in your Express server? What do you get with this:
routes.post('/incidents', (req, res, next) => console.log(req.body); next())
My guess is req.body
is either undefined or a string.
Are you using
body-parser
in your Express server? What do you get with this:routes.post('/incidents', (req, res, next) => console.log(req.body); next())
My guess is
req.body
is either undefined or a string.
The main reason that express didn't recognized the body parser was the lack of content-type on requisition. This clue gave me a light tho. Thanks for all ❤️
node
version - 12.16.1celebrate
version - 12.0.1I'm using Celebrate in my router.js file, every single route with 1 type of requisition is working, but i'm having issues with 2 types of requisitions. In this case bellow, my headers ckeckout is working normally, but Celebrate didn't recognize the second param BODY. Specifically the variables
Result in Insomnia: