const AppError = require('../utils/appError')

module.exports = function requireJsonBody(req, res, next) {
    const methods = ['POST', 'PUT', 'PATCH']

    if (!methods.includes(req.method)) {
        return next()
    }

    if (!req.is('application/json')) {
        return next(new AppError('请求体必须为 application/json', 415))
    }

    next()
}
