Search code examples
ember.jscorsember-cli

Setting CORS for static files on ember-cli server


How do I set CORS on requests for fonts files (or any other static resource) on the built in ember-cli server?

This is the error message just for reference:

Font from origin 'http://some-domain:4200' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:61277' is therefore not allowed access.

Solution

  • Add the following to ENV in config/environment.js:

    module.exports = function(environment) {
        contentSecurityPolicyHeader: 'Content-Security-Policy',
        contentSecurityPolicy: {
          // ... other stuff here
          'font-src': "'self' http://some-domain:4200",
        },
    }