perusio / drupal-with-nginx

Running Drupal using nginx: an idiosyncratically crafted bleeding edge configuration.
854 stars 246 forks source link

CORS #222

Open develnk opened 9 years ago

develnk commented 9 years ago

I faced with problem where using subdomain and can not execute requests between subdomains. This problem related with CORS. Need to add header: "Access-Control-Allow-Origin", "Access-Control-Allow-Methods", "Access-Control-Allow-Headers" to allow browser execute requests.

I use angularjs as frontend and drupal as backend. Thanks.

perusio commented 9 years ago

Well It's quite easy. What Just add the headers in a file, call it CORS basic and include it. For example:

## Basic CORS support.
add_header Access-Control-Allow-Origin '$http_origin' always;
add_header Access-Control-Allow-Credentials true always;
add_header Access-Control-Allow-Headers 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
add_header Access-Control-Expose-Headers 'Authorization';

It depends on which headers and methods you want to allow. The above was used for an app where a JWT was being used. Therefore the Authorization header.

perusio commented 9 years ago

I will add a config file for this soon. Thanks for opening this issue. Now we live in a APi + frontend world indeed.

matthewboman commented 5 years ago

include it where?