0

I am building my first app using ionic framework. I run into the following issue. I have a nodejs rest api hosted in the cloud. When I run my app using ionic serve and I fetch some data it does work. But when I do it from my device (using ionic run android) it doesnt work. I've read something about cordova-plugin-whitelist, but I have it and still doesnt work.

ionic.project
{
"name": "myApp",
"app_id": "",
"proxies": [
  {
    "path": "/contacts",
    "proxyUrl": "https://myapp.herokuapp.com/contacts"
  }
]
}

In config.xml I have both of this tags:

<access origin="*"/>
<allow-navigation href="*" />

I forgot to mention that I tried accessing to this other api https://api.chucknorris.io/jokes/random and it has no problems with it. Maybe somethings wrong with my nodejs REST service?

3
  • remove platform and add it again..!then run ionic run android Commented Aug 5, 2016 at 1:53
  • Didnt work. I think it migth have something to do with my service and not with ionic. Commented Aug 7, 2016 at 21:50
  • This plugin will resolve this issue when testing your applicationn within a Chrome Borwser: Allow-Control-Allow-Origin: * Commented Nov 24, 2017 at 13:00

3 Answers 3

1

I went through this same problem, I tried all possibilities. I installed the cordova-plugin-whitelist plugin. It includes the settings in config.xml, the <meta> with CSP (Content-Security-Policy) and even then I couldn't solve the problem. I did all possible procedures and it still doesn't work.

It worked on the ionic serve and ionic run -l but it did not work on the device. When I was giving up, I realized that when I included the URLs of other servers it worked, and not worked for my URL. I thought it was a problem in my server or in my API.

Until I saw that my constant referring to URL was without http, because as it did in normal programming in AngularJS, put the constant //api.example.com/, and leaves the browser responsible for including it. But it does not happen on the device, so I did not access my API.

I do not know if that was your case, but it took me a long time to find out and I'd like to share it with you.

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

3 Comments

"Until I saw that my constant referring to URL" how did you check that on device
@manishkumar You can see using the AVD via command line, see it: developer.android.com/studio/run/emulator-commandline.html
how in the world its work for you, application cant detect the URL // without HTTP://
0

In my case ,I just installed cordova-plugin-whitelist plugin .And the issue was resolved.Hope it helps someone.

Happy coding :)

Comments

-1

Add this meta tag in your index.html

 <meta http-equiv="Content-Security-Policy" content="default-src *; style-src   'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.