lib/cors.js
function getResponseHeaders (req) {
  let corsHeaders = {};
  if (req.swagger) {
    let headers = [];

    if (req.method !== "OPTIONS") {
      // This isn't a preflight request, so the operation's response headers take precedence over the OPTIONS headers
      headers = getOperationResponseHeaders(req.swagger.operation);
    }

    if (req.swagger.path) {
      // Regardless of whether this is a preflight request, append the OPTIONS response headers
      headers = headers.concat(getOperationResponseHeaders(req.swagger.path.options));
    }

    // Add the headers to the `corsHeaders` object.  First one wins.
    headers.forEach((header) => {
      if (corsHeaders[header.name] === undefined) {
        corsHeaders[header.name] = header.value;
      }
    });
  }

  return corsHeaders;
}
function getResponseHeaders (req) {
  let corsHeaders = {};
  if (req.swagger) {
    let headers = [];

    if (req.method !== "OPTIONS") {
      // This isn't a preflight request, so the operation's response headers take precedence over the OPTIONS headers
      headers = getOperationResponseHeaders(req.swagger.operation);
    }

    if (req.swagger.path) {
      // Regardless of whether this is a preflight request, append the OPTIONS response headers
      headers = headers.concat(getOperationResponseHeaders(req.swagger.path.options));
    }

    // Add the headers to the `corsHeaders` object.  First one wins.
    headers.forEach((header) => {
      if (corsHeaders[header.name] === undefined) {
        corsHeaders[header.name] = header.value;
      }
    });
  }

  return corsHeaders;
}
function getResponseHeaders ( req ) { let corsHeaders = { } ; if ( req . swagger ) { let headers = [ ] ; if ( req . method !== "OPTIONS" ) { // This isn't a preflight request, so the operation's response headers take precedence over the OPTIONS headers headers = getOperationResponseHeaders ( req . swagger . operation ) ; } if ( req . swagger . path ) { // Regardless of whether this is a preflight request, append the OPTIONS response headers headers = headers . concat ( getOperationResponseHeaders ( req . swagger . path . options ) ) ; } // Add the headers to the `corsHeaders` object.  First one wins. headers . forEach ( ( header ) => { if ( corsHeaders [ header . name ] === undefined ) { corsHeaders [ header . name ] = header . value ; } } ) ; } return corsHeaders ; }
Returns an object containing the CORS response headers that are defined in the Swagger API.
If the same CORS header is defined for multiple responses, then the first one wins.

@param   {Request}   req
@returns {object}
Returns an object containing the CORS response headers that are defined in the Swagger API . If the same CORS header is defined for multiple responses then the first one wins .