mirror of
https://github.com/sergeyyarkov/modbus-logger.git
synced 2026-10-11 10:28:51 +03:00
20 lines
458 B
JavaScript
20 lines
458 B
JavaScript
/**
|
|
* Validate request body
|
|
* @param {import('yup').Schema} schema
|
|
*/
|
|
export function validateBodyMiddleware(schema) {
|
|
/**
|
|
* @param {import('express').Request} req
|
|
* @param {import('express').Response} res
|
|
* @param {import('express').NextFunction} next
|
|
*/
|
|
return async (req, res, next) => {
|
|
try {
|
|
await schema.validate(req.body);
|
|
next();
|
|
} catch (error) {
|
|
return res.status(400).send(error.message);
|
|
}
|
|
};
|
|
}
|