@Dehibernate wrote:
Hi there! I'm building a small app, which needs to synchronise with an Express (NodeJS) server on my Raspberry Pi. So far that consists of uploading or downloading a JSON object to/from the server which is on my local network. I want to deploy the app on both Android and Windows 10, but I'm having big issues with the latter.
I understand CORS is an obstacle to external connections, so I've setup a proxy in my ionic.project file. The proxy routes "/pi" to "http://raspberrypi:3535/".
I've also added cordova-plugin-whitelist to the project and the following lines of code:
In config.xml -<allow-navigation href="http://*/*" />
In index.html -<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
I have a service with the following download function:
this.download = function() { return $http.get(url) .success(function(data, status, headers, config) { $ionicPopup.alert({ title: 'HTTP GET Succeeded', template: JSON.stringify(status) }); $ionicPopup.alert({ title: 'HTTP GET Succeess status', template: JSON.stringify(data) }); }) .error(function(data, status, headers, config) { $ionicPopup.alert({ title: 'HTTP GET Error status', template: JSON.stringify(status) }); $ionicPopup.alert({ title: 'HTTP GET Error status', template: JSON.stringify(data) }); }); };
The variable url is declared higher up and has a default value of "/pi", which only changes to "http://raspberrypi:3535/", when running on Android.
Note that I'm using alerts because "ionic run windows -l -c" doesn't work - the app freezes on startup.
So far I've confirmed that the function works perfectly in serve mode on Chrome/Edge, and as an app on Android. But when I deploy it on Windows 10 (as UWP app), It returns a status 500 error, and data and config are empty or undefined (I couldn't see through the alerts).
I've tried using XMLHttpRequest instead and I get the exact same results, only Windows 10 doesn't work. I've also tried using the full address "http://raspberrypi:3535" for the HTTP GET request, but then I get a code 0, presumably because CORS is blocking it.
I'm completely stumped and I don't see why it doesn't work, given that all other platforms have no issues. Another (possibly unrelated) thing that confuses me is that both Windows 10 UWP apps and the Edge browser return 'true' when invoking ionic.Platform.isEdge(), so presumably they use a similar platform.
If anyone can think of any solution to this, I'd be eternally grateful! I've been scouring the internet for solutions all day and none of them have worked.
Thank you in advance!
Posts: 1
Participants: 1