Reputation: 63
I am developing an android app using Meteor and am having problems displaying images from external sources.
The following <img>
tag should displays an image from the google maps api based on the latitude and longitude:
<img src="http://maps.googleapis.com/maps/api/staticmap?center={{loc.lat}},{{loc.lng}}&zoom=15&size=600x300&maptype=roadmap&markers=color:blue%7C{{loc.lat}},{{loc.lng}}" />
Though this works in the browser, I get the below error on the server when trying to run it on an android device
XMLHttpRequest cannot load http://10.0.2.2:3000/sockjs/info?cb=p4ej3xginv. Origin http://meteor.local is not allowed by Access-Control-Allow-Origin.
Do I need to put the 'google maps api' domain in some kind of 'Whitelist' like when working with Phonegap.
If so, how do we do this in Meteor?
Upvotes: 3
Views: 2627
Reputation: 4820
Yep, starting from 1.0.4, "Meteor Cordova apps no longer allow access to all domains by default."
So from now on, in your mobile-config.js
file, you will have to call App.accessRule for every external domain you may load content from.
So in your case, adding:
App.accessRule('http://maps.googleapis.com/*');
at the end of your mobile-config.js
file should do the trick.
Upvotes: 11
Reputation: 159
Adding access rules to mobile-config.js fixes loading of external images in Cordova apps.
App.accessRule('https://www.mycdn.com/*');
meteor run ios
This is an alternative option, my guess is there might be some difference how this is built:
<access origin="https://www.mycdn.com/*"/>
meteor run ios
Initially I was trying with browser-policy package and setting BrowserPolicy.content.allowImageOrigin("https://www.mycdn.com/*");
, but apparently that is a different story?
Upvotes: 4