DirtDiver DirtDiver - 11 months ago 109
Node.js Question

Angular 2 Electron - Consuming REST-API

I have an Electron App, which uses Angular 2 - in order to work i needed to modify

<base href="/">
<base href="./">
, which is a relative path in the file system. But now the API doesn't work anymore (Webclient on localhost works fine, but not Electron Client).

I access the API via proxy.conf.json

"/api": {
"target": "",
"secure": false

And the error message in the JavaScript Console of Chromium / Electron is:

Failed to load resource: net::ERR_FILE_NOT_FOUND

How can i tell Electron to access the local resources via relative Path and consume the API via HTTP?

Answer Source

We enabled CORS on the Webserver and this setting allowed us to consume the REST-API from a different URL.

See https://en.wikipedia.org/wiki/Cross-origin_resource_sharing for details.