Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 840
leojh Avatar asked Jan 02 '15 01:01

leojh


2 Answers

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",
    },
}
like image 114
Andrew Hacking Avatar answered Oct 31 '22 20:10

Andrew Hacking


I tried adding the CSP settings but it was unsuccessful for me. I still got CORS errors for font files being referenced from my Ember app's CSS. In another post I saw someone mention ember-cli-cors which I tried and seemed to solve the issue for me. It just adds CORS headers allowing requests from everywhere to all resources which is exactly what I needed to get all resources to load properly in my local dev environment serving the Ember app assets using ember-cli's built in ember serve command to another local development server running a Python app serving my index.html from Redis(ember-cli-deploy style).

like image 21
munsellj Avatar answered Oct 31 '22 20:10

munsellj