Files
FACULTATE-LICENTA/UC/backend/src/middlewares/checkJson.js
T

16 lines
403 B
JavaScript

const {httpStatus} = require("../helpers/httpResponses");
function checkJson(req, res, next) {
if(req.method === 'GET'){
next()
}
if (['POST', 'PUT', 'PATCH'].includes(req.method) && req.headers['content-type'] !== 'application/json') {
return res.status(httpStatus.BAD_REQUEST).json({message: "Body missing in action."});
}
next();
}
module.exports = checkJson;