Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 为ember cli服务器上的静态文件设置CORS_Ember.js_Cors_Ember Cli - Fatal编程技术网

Ember.js 为ember cli服务器上的静态文件设置CORS

Ember.js 为ember cli服务器上的静态文件设置CORS,ember.js,cors,ember-cli,Ember.js,Cors,Ember Cli,如何在内置的ember cli服务器上对字体文件(或任何其他静态资源)的请求设置CORS 此错误消息仅供参考: 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. Or

如何在内置的ember cli服务器上对字体文件(或任何其他静态资源)的请求设置CORS

此错误消息仅供参考:

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.

将以下内容添加到config/environment.js中的ENV中:

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

我尝试添加CSP设置,但没有成功。我仍然从我的Ember应用程序的CSS中引用字体文件时出现CORS错误。在另一篇帖子中,我看到有人提到了,我试着用它解决了这个问题。它只是添加了CORS头,允许从任何地方向所有资源发出请求,这正是我需要在本地开发环境中正确加载所有资源的地方,该环境使用Ember cli的内置
Ember-service
命令为Ember-app资产提供服务,并将另一个本地开发服务器运行一个Python应用程序,该应用程序从Redis(ember cli deploy style)。

如果我能详细说明的话,您可以通过使用CSP来避免COR和额外的飞行前请求,CSP首先允许您的应用程序进行跨源请求。@Andrewacking坦白地说,这是我第一次不得不操作CSP。除此之外,我还将我的余烬应用程序嵌入到一个已经存在的应用程序中,这使得事情变得更加复杂。让我进一步研究一下。我只是在无法通过CSP设置策略时才使用CORS,这就是为什么我关注这个问题,因为你说你正在使用Ember CLI为你的应用程序提供服务。除上述内容外,我相信你还需要按照munsellj@AkshayRawat,非源服务器(即不是ember CLI服务器)将需要具有CORS标头,以允许浏览器接受来自服务器的响应。这些其他服务器将需要指定来源(或指定通配符)。ember CLI服务器通常不会为来自其他来源的客户端提供服务,因此通常不使用CORs头,而只是为正在开发的浏览器客户端设置CSP头。CSP标题是一个白名单,允许浏览器访问非原始站点,作为生产的最佳实践。CSP和CORs从问题的不同方面工作。