angularjs - PhoneGap doesn't want to use REST service no matter what I do -
i have phonegap app using angularjs with. i'm using pretty simple $http call node backend:
$http.get("http://localhost:6969/random") .then(function(response) { $scope.images = response.data; });
no matter what, phonegap never hits backend. have tested in normal browser , works expected.
i have read bunch , people fix using whitelisting, in config.xml
, whitelisting open can be:
<plugin name="cordova-plugin-whitelist" source="npm" spec="1.1.0" /> <allow-navigation href="*" subdomains="true" /> <allow-intent href="*" subdomains="true"/> <access origin="*" subdomains="true"/> <!-- required ios9 -->
what have change? been wrestling bug few days off , on , it's bit annoying not able create new cool features in free time.
edit: serving app using phonegap serve
, testing using phonegap developer app.
i suggest content security policy might need modified include connect-src clause specify ajax requests can go to.
taking csp meta tag posted in comments:
<meta http-equiv="content-security-policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src: 'self' 'unsafe-inline' 'unsafe-eval'" />
i suggest amending open ajax requests anywhere, see if helps reign in domain(s) want support after.
suggested csp be:
<meta http-equiv="content-security-policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src *">
if works , want lock down 1 domain later you'd want like:
<meta http-equiv="content-security-policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src http://api.mydomain.com">
additionally think need change app's code connect server hostname or ip address, so on device doesn't confuse 'localhost' device , try make connection port 6969 on device.
so:
$http.get("http://localhost:6969/random")
may need become:
$http.get("http://myhost.mydomain.com:6969/random")
or
$http.get("http://xxx.xxx.xxx.xxx:6969/random")
there's resources on online:
Comments
Post a Comment