Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Deployemnt of Angular6 & NodeJS app on Cloud Foundary

former_member603224
Discoverer
0 Kudos

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 ?

1 ACCEPTED SOLUTION

former_member603224
Discoverer
0 Kudos

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

1 REPLY 1

former_member603224
Discoverer
0 Kudos

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