Enabling CORS support on Elemental Live

AWS Elemental Live’s REST API can be accessed directly from Javascript running in the browser, but if authentication is enabled on the Elemental Live you’ll hit problems due to Cross-Origin Resource Sharing (CORS) restrictions.

Elemental Live (as of V2.13) doesn’t support CORS requests by default. You could solve this by using WebCentre as a proxy server between the browser and Elemental Live, but here we’ll show how to modify Elemental Live HTTP settings to handle CORS.

You’ll need to be familiar with logging in to the Elemental Live system via SSH, basic Linux commands, and a Linux text editor like vim or nano.

  • Log into Elemental Live via SSH. (On Windows, PuTTY is a good tool to use)
  • Locate the configuration files in /etc/httpd/conf.d

  • Make a backup copy of the configuration file before editing it!
  • cp elemental_se_apache.conf elemental_se_apache.conf.bak
  • Now, add a new “location” section for API calls in elemental_se_apache.conf
  • sudo vi elemental_se_apache.conf
  • Insert this section as shown.
    <Location /api/>
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
    Header always set Access-Control-Allow-Headers "origin, content-type,x-auth-key,x-auth-user,x-auth-expires"
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ $1 [R=204,L]
    </Location>

  • Save the file, and restart your Elemental Live server.
  • sudo shutdown -r now