2019 Feb 11 9:46 AM
Hi,
I have an Angular 6 application which is communicating to Node services. I have deployed both app (Angular & Node app) to cloud foundary. On SCP, both app are residing in a common space, but source code are inside diffrent folders. In the cockpit, i can see two diffrent apps. After deploying both the app, i ran a command i.e. "cf apps" which is giving me 2 diffrent url for both applications.
Angular: https://simple-crud-app.cfapps.eu10.hana.ondemand.com/
Node: https://simplehttpserver-zany-giraffe.cfapps.eu10.hana.ondemand.com/
When i am running angular url in browser, it is giving me CORS error because both application is running on diffrent urls.
Error: Access to XMLHttpRequest at 'https://simplehttpserver-zany-giraffe.cfapps.eu10.hana.ondemand.com/' from origin 'https://simple-crud-app.cfapps.eu10.hana.ondemand.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
For angular app, i am using "staticfile_buildpack" in the manifest.yml file and for node app i am using "nodejs_buildpack" as a build pack.
Can someone please help me to indentify the root cause of this issue and let me know how to fix it ?
2019 Feb 14 5:19 AM
I have added the CORS header before sending the response to client and it's working for me. Here is the code snippet below.
response.header('Access-Control-Allow-Origin', '*');
HTH
2019 Feb 14 5:19 AM
I have added the CORS header before sending the response to client and it's working for me. Here is the code snippet below.
response.header('Access-Control-Allow-Origin', '*');
HTH