0
votes

I have an embedded device that I want to connect to from my app through http. Therefore I have to use Ionic Proxy. So in my project file I have:

 {
  "name": "MyApp",
  "app_id": "",
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "http://192.168.0.100"
    }
  ]
}

But whenever my App (running in chrome) tries to get some JSON data from my embedded server, I get an error 500 even though it returns the correct JSON when I visit the API from my browser.

Here's the service I am using:

angular.module('starter.services', ['ngResource'])
.factory('device_status', function ($resource) {
    return $resource('/api/device_status');
});

And when I try out the API from browser I am visiting this URL:

http://192.168.0.100/device_status

and getting:

{"mode":"STANDBY","niveau":3,"hours":1,"minutes":30,"nightmode":1}

Also, I have an internal server on my localhost that returns exactly the same JSON, and if I test against this, it works fine.

1

1 Answers

0
votes

An alternative to what you are doing could be setting up a CORS Proxy.

1. Install the proxy by typing this command in the terminal:

npm install -g corsproxy

2. Start the proxy with:

corsproxy

3. After starting the proxy you should be able to see where does the proxy runs (check the output in the terminal). Normally it will look like

http://localhost:9292

4. Then you should be able to make requests like:

http://yourproxy/yourapiendpoint