2017-06-26 19:58:58 +02:00
|
|
|
/*
|
|
|
|
express middleware that sends a 406 Unacceptable
|
|
|
|
response if an incoming request's Content-Type
|
|
|
|
header does not match `type`
|
|
|
|
*/
|
|
|
|
const requestsOfType = type => (req, res, next) => {
|
|
|
|
if (req.get('content-type') != null && !req.is(type)) {
|
2017-12-08 20:50:53 +01:00
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
console.log('in requests of type error');
|
|
|
|
}
|
2017-06-26 19:58:58 +02:00
|
|
|
return next({ statusCode: 406 }); // 406 UNACCEPTABLE
|
|
|
|
}
|
|
|
|
|
|
|
|
return next();
|
|
|
|
};
|
|
|
|
|
|
|
|
export default requestsOfType;
|
|
|
|
export const requestsOfTypeJSON = () => requestsOfType('application/json');
|