UNPKG

express-json

Version:

A middleware for Express that sets Content-Type to text/plain if Accept header doesn't contain application/json.

13 lines (12 loc) 366 B
module.exports = function () { return function (req, res, next) { var json = res.json; res.json = function () { if (!req.headers.accept || req.headers.accept.indexOf('application/json') === -1) { res.contentType('text/plain'); } json.apply(res, arguments); }; next(); }; };