Cancel
Showing results for 
Search instead for 
Did you mean: 

Connect Angular App to Node.js server on Mindsphere (Authentification ?)

Experimenter
Experimenter

I have successfully pushed both applications (Angular UI and node server) to Cloudfoundry.

Both applications can be opened through the Mindsphere launchpad / the browser. 

For example, calling https://<tanent>-nodeserver-<region>.mindsphere.io/api/data displays entries of a database on the browser.

 

However, I am unable to get the database content through the Angular app. Whenever I try to fetch the url, I get a CORS error. Here is a screenshot of the error and the corresponding code section:

 

apiError.PNG

 

My component structure on the Mindsphere Developer Cockpit:

UI:

  1. ngChart (cf direct url of UI), endpoint "/**"
  2. nodeServer (cf direct url of server), endpoint "/nodeServer/api/data*

server:

  1. nodeServer (cf direct url to server), endpoint "/**"

CSP for both apps: style-src * 'unsafe-inline'; script-src 'self' 'unsafe-inline' static.eu1.mindsphere.io; img-src * data:;

 

 

I have tried to allow CORS on the server side: 

 

var cors = require('cors');
app.use(cors());
app.options('*', cors());
 
However, the error did not change. I would be glad if someone has an idea ...

 

2 REPLIES 2

Re: Connect Angular App to Node.js server on Mindsphere (Authentification ?)

Siemens Valued Contributor Siemens Valued Contributor
Siemens Valued Contributor

I think you have two different apps. UI-app and Server-app. From UI-app you want to call API endpoint from another app i.e server-app.  You can use following option:

In the UI-app, you can add more components for backend server. In your case "nodeServer" component into UI app. So all calls to server happens from single app.  Details here resolution

 

 

 

 

 

 

Re: Connect Angular App to Node.js server on Mindsphere (Authentification ?)

Experimenter
Experimenter

I have already tried this solution but it didn't work. My component structure can be seen below.

 

server:


NodeEndpoint.pngnodeServer componentsUI:


ngComponents.pngUI componentsIf I understand it correctly, I should be able to call https://<tenant-name>-ngChart-<provider-name>.<region>.mindsphere.io/nodeServer

 

But whenever I try that I get the "404 Error". If I try to call ...../nodeServer/api/data then I get "Cannot GET /nodeServer/api/data".

 

Apparently, I am doing something wrong ...