0

I have an Angular application, with an API, that connects and makes calls to a database established in a server with a public IP.

When I create the Angular project with ng serve everything works fine, I can do the calls, the server receives the requests etc Then I wanted to export it to an apk using cordova. When I exuecute ng build --prod --aot ;; cordova build browser ;; cordova run browser --port=3000 everything works fine too. I was able to create the app and everything works fine.

My problem starts when I want to use it in a real device or an emulator. The app is created and you can enter but the calls to the server don't work anymore. I use ng build --prod --aot ;; cordova build android ;; cordova run android --port=3000

So I have to questions:

first, how could I debug this?

Second, do you have any ideas why this could happen?

Thank you

2 Answers2

0

Documentaion: 'The ng build command with the --prod meta-flag (ng build --prod) compiles with AOT by default.'

On the topic of your problem, I assume that you have forgotten to set the base href tag to be './' instead of '/'. Try this out:

ng build --prod --base-href . ;; cordova run android
Ivan Mihaylov
  • 434
  • 2
  • 9
0

Solved, I needed to allow access in the html like:

responseContext.getHeaders().add( "Access-Control-Allow-Origin", "*");

More details: WebView showing ERR_CLEARTEXT_NOT_PERMITTED although site is HTTPS