{"size": 659, "ext": "js", "max_stars_repo_path": "src/middleware/ContentTypeHeader.js", "max_stars_repo_name": "nuxy/nodejs-es6-restful-jsonapi-seed", "max_stars_repo_stars_event_min_datetime": "2018-04-09T22:37:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T13:46:19.000Z", "max_issues_repo_path": "src/middleware/ContentTypeHeader.js", "max_issues_repo_name": "nuxy/nodejs-es6-restful-jsonapi-seed", "max_issues_repo_issues_event_min_datetime": "2018-04-05T18:11:47.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-30T21:37:18.000Z", "max_forks_repo_path": "src/middleware/ContentTypeHeader.js", "max_forks_repo_name": "nuxy/nodejs-es6-restful-jsonapi-seed", "max_forks_repo_forks_event_min_datetime": "2018-09-01T18:59:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-20T13:10:48.000Z"}
{"max_stars_count": 7, "max_issues_count": 3, "max_forks_count": 4, "avg_line_length": 21.9666666667, "max_line_length": 77, "alphanum_fraction": 0.6312594841}
'use strict';

import config from 'config';

/**
 * Middleware to send JSON API supported Content-Type header.
 *
 * @see http://jsonapi.org/format/#content-negotiation-servers
 *
 * @export default {Function}
 */
export default (req, res, next) => {

  // Exclude documentation requests.
  if (process.env.NODE_ENV === undefined && /^\/ap[ip]-doc/.test(req.path)) {
    return next();
  }

  // Skip headers on empty response.
  const send = res.send;
  res.send = function(body) {
    if (config.get('server.allowEmptyBody') === false || body) {
      res.set('Content-Type', 'application/vnd.api+json');
    }
    send.call(this, body);
  };

  next();
};
