_/Chapter17/hobnob-client/api/src/middlewares/check-content-length/index.js
// Our endpoint would all be expecting a payload of some sort
Our endpoint would all be expecting a payload of some sort
Our endpoint would all be expecting a payload of some sort
function checkContentLength (req, res, next) {
  if (
    ['POST', 'PATCH', 'PUT'].includes(req.method)
    && req.headers['content-length'] === '0'
  ) {
    res.status(400)
    res.set('Content-Type', 'application/json');
    res.json({ message: 'Payload should not be empty' });
    return;
  }
  next();
}
function checkContentLength ( req , res , next ) { if ( [ 'POST' , 'PATCH' , 'PUT' ] . includes ( req . method ) && req . headers [ 'content-length' ] === '0' ) { res . status ( 400 ) res . set ( 'Content-Type' , 'application/json' ) ; res . json ( { message : 'Payload should not be empty' } ) ; return ; } next ( ) ; }
Our endpoint would all be expecting a payload of some sort
Our endpoint would all be expecting a payload of some sort
// If the request is a POST, PATCH or PUT request