[英]Angular2 in nginx - CORS header 'Access-Control-Allow-Origin' missing
So I have taken the heroes tutorial from Angular 2, used it with an angular-cli project. 因此,我从Angular 2那里学习了英雄教程,并将其与angular-cli项目结合使用。 Running ng serve and using in memory api, it works.
运行ng serve并在内存api中使用它可以正常工作。
Changed the server url to point to my tomcat server that is providing a rest api. 更改了服务器URL,使其指向提供REST API的Tomcat服务器。 I have tested this with curl and it gives back data.
我已经用curl进行了测试,它可以返回数据。
I then built it for production and put the resulting bundles into nginx on the same machine as tomcat. 然后,我将其构建用于生产,并将生成的捆绑包与tomcat放在同一台计算机上的nginx中。
Run in Firefox, get correct page but no data. 在Firefox中运行,获取正确的页面,但没有数据。 Console shows the GET is OK.
控制台显示GET正常。 But I do get
但是我得到了
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://centos7:8080/heroes/heroes. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
Other questions in StackOverFlow on this topic say that both must be in the same domain, which they are, the tomcat server is centos7:8080/heroes/heroes and the nginx server is centos7/ 关于此主题的StackOverFlow中的其他问题表明,两者都必须位于同一个域中,tomcat服务器为centos7:8080 / heroes / heroes,而nginx服务器为centos7 /
Should I have to open up CORS? 我是否必须开放CORS? I have seen http://enable-cors.org/server_nginx.html so I need to add this in nginx.conf?
我看过http://enable-cors.org/server_nginx.html,所以需要在nginx.conf中添加它吗?
Does anyone have any ideas? 有人有什么想法吗?
Regards 问候
So I am not if this is the abolute answer but it removed the CORS error in browser console. 因此,如果这是正确的答案,那么我不是,但是它消除了浏览器控制台中的CORS错误。
In my grails 3 rest api application, I added the grails 3 COR interceptor https://github.com/appcela/grails3-cors-interceptor . 在我的grails 3 rest api应用程序中,我添加了grails 3 COR拦截器https://github.com/appcela/grails3-cors-interceptor 。
I now get a different problem but I will raise that in a separate question. 我现在遇到另一个问题,但我将在另一个问题中提出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.