0

I know that question came up many times, but I've now seached the web about two days and tested so many cases, that I think it is time to call some help.

My Case: I've an ionic 2 application with a external API written in node and authenticated with Auth0 and JWT. The main problem is that the request through Http within an android emulated app is not calling the API. It is like the app can not call outside itself. That came up also for and shared ionic cloud app.

How I produce the error: Before all I installed the whitelist plugin from cordova and allowed EVERYTHING (here the config.xml: https://hastebin.com/fekuvijaxi.xml). I have also added the http-equiv to my index.html (https://hastebin.com/gocevomayo.xml). Now I've stared the app with cordova ionic cordova run android -lcs. My device below.

The error I can archive from my http wrapper (import { AuthHttp } from 'angular2-jwt';) is that:

[14:47:36] console.log: http://localhost:8080/api/v1/auth/login [14:47:36] console.log: {"_body":{"isTrusted":true},"status":0,"ok":false,"statusText":"","headers":{},"type":3,"url":null} 

My Service function: https://hastebin.com/zudepameca.coffeescript

Device: Serial: emulator-5584 Emu Version: 26.1.2-4077558 Android: 7.1 (Nougat) - API 25

Ionic Info: global packages:

@ionic/cli-utils : 1.5.0 Cordova CLI : 7.0.1 Ionic CLI : 3.5.0 

local packages:

@ionic/app-scripts : 2.0.2 @ionic/cli-plugin-cordova : 1.4.1 @ionic/cli-plugin-ionic-angular : 1.3.2 Cordova Platforms : android 6.2.3 browser 4.1.0 ios 4.4.0 Ionic Framework : ionic-angular 3.5.3 

System:

Node : v7.8.0 OS : macOS Sierra Xcode : Xcode 8.3.3 Build version 8E3004b ios-deploy : 1.9.1 ios-sim : 5.1.0 npm : 5.3.0 
8
  • A status of 0 is likely to be a CORS issue (see my answer here) have you verified that is not the problem? Commented Jul 22, 2017 at 22:33
  • @0mpurdy the app is not calling the API so it can not be a CORS issue. My server has descriped that allready hastebin.com/iqodakanah.php Commented Jul 22, 2017 at 22:53
  • When you say that it is not calling the API do you mean that it is not attempting to call the API, as in you have a mock service, or you are not seeing it access the API? Commented Jul 22, 2017 at 23:03
  • How do you know that the app is not calling the API? Have you monitored any http traffic over the wire or checked the server log to see if the request is ever reaching the machine? Commented Jul 23, 2017 at 5:09
  • 1
    @0mpurdy - okay it is now working. I changed my http-equiv to that <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: * 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> and it worked... for now. Commented Jul 26, 2017 at 8:40

1 Answer 1

0

Thanks to @0mpurdy and @captain_jim1 for there time to help me.

How I solved this issue:

At first I'd made sure the problem was not on server side, so I logged any incomming requests. Until I got none, I'd know it was something wrong with my APP.

So in my APP I logged from the end of the problem to the beginning, from every function and observable. And I got an error (listed above). So I searched here and in the web for a solution and found one:

I just had to add this line <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: * 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> into my app/index.hmtl. As descriped here: https://github.com/apache/cordova-plugin-whitelist#content-security-policy

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.