lib/cors-anywhere.js
/**
 * Adds CORS headers to the response headers.
 *
 * @param headers {object} Response headers
 * @param request {ServerRequest}
 */
Adds CORS headers to the response headers.
@param headers {object} Response headers
@param request {ServerRequest}
Adds CORS headers to the response headers . @param headers { object } Response headers @param request { ServerRequest }
function withCORS(headers, request) {
  if(!request.corsAnywhereRequestState.enableCookies){
      headers['access-control-allow-origin'] = '*';
  }else{
      headers['access-control-allow-origin'] = request.headers.origin;
      headers['access-control-allow-credentials'] = true;
  }
  var corsMaxAge = request.corsAnywhereRequestState.corsMaxAge;
  if (request.method === 'OPTIONS' && corsMaxAge) {
    headers['access-control-max-age'] = corsMaxAge;
  }
  if (request.headers['access-control-request-method']) {
    headers['access-control-allow-methods'] = request.headers['access-control-request-method'];
    delete request.headers['access-control-request-method'];
  }
  if (request.headers['access-control-request-headers']) {
    headers['access-control-allow-headers'] = request.headers['access-control-request-headers'];
    delete request.headers['access-control-request-headers'];
  }
  headers['access-control-expose-headers'] = Object.keys(headers).join(',') + ",Given,Given2";
  return headers;
}
function withCORS ( headers , request ) { if ( ! request . corsAnywhereRequestState . enableCookies ) { headers [ 'access-control-allow-origin' ] = '*' ; } else { headers [ 'access-control-allow-origin' ] = request . headers . origin ; headers [ 'access-control-allow-credentials' ] = true ; } var corsMaxAge = request . corsAnywhereRequestState . corsMaxAge ; if ( request . method === 'OPTIONS' && corsMaxAge ) { headers [ 'access-control-max-age' ] = corsMaxAge ; } if ( request . headers [ 'access-control-request-method' ] ) { headers [ 'access-control-allow-methods' ] = request . headers [ 'access-control-request-method' ] ; delete request . headers [ 'access-control-request-method' ] ; } if ( request . headers [ 'access-control-request-headers' ] ) { headers [ 'access-control-allow-headers' ] = request . headers [ 'access-control-request-headers' ] ; delete request . headers [ 'access-control-request-headers' ] ; } headers [ 'access-control-expose-headers' ] = Object . keys ( headers ) . join ( ',' ) + ",Given,Given2" ; return headers ; }
Adds CORS headers to the response headers.
Adds CORS headers to the response headers .
//the code below sets which headers must be returned in the response //i've added given, given2 as who ever sends out a request, is expecting their cookies as either value.