drupal-with-nginx icon indicating copy to clipboard operation
drupal-with-nginx copied to clipboard

CORS

Open develnk opened this issue 9 years ago • 3 comments

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.

develnk avatar Jul 16 '15 05:07 develnk

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 avatar Jul 16 '15 20:07 perusio

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

perusio avatar Jul 16 '15 20:07 perusio

include it where?

matthewboman avatar Sep 12 '18 22:09 matthewboman