
CORS Essentials
By :

Custom code is the best way to implement CORS in Drupal, using techniques we have covered. There are also some contributed Drupal modules for CORS. Be mindful of Drupal core API differences among versions: Drupal 6, 7, 8. When Drupal 8 is released, support for Drupal 6 will end.
CORS headers may be added to endpoints created in a custom module or in the template.php
file in your theme.
The CORS headers can be added:
With the Drupal API function drupal_add_http_header
By configuring .htaccess
to send headers, for example, using Apache's mod.headers
By explicitly setting the header with code in a custom module or theme template
The following custom function adds CORS headers in Drupal 7 for a JSON application, with the wildcard to allow requests from all domains, and allows GET
, PUT
, POST
, and DELETE
methods:
function set_custom_headers() { drupal_add_http_header('Content-Type', 'application/json...
Change the font size
Change margin width
Change background colour