简体   繁体   中英

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. Running ng serve and using in memory api, it works.

Changed the server url to point to my tomcat server that is providing a rest api. I have tested this with curl and it gives back data.

I then built it for production and put the resulting bundles into nginx on the same machine as tomcat.

Run in Firefox, get correct page but no data. Console shows the GET is OK. 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/

Should I have to open up CORS? I have seen http://enable-cors.org/server_nginx.html so I need to add this in 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.

In my grails 3 rest api application, I added the grails 3 COR interceptor https://github.com/appcela/grails3-cors-interceptor .

I now get a different problem but I will raise that in a separate question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM