Problem Ionic Http Requests

1

I have my api rest done in nodejs (express) which is local link , my configuration of cors de my api rest it's

const cors = require('cors')
app.use(cors());

then in my ionic application when I start ionic serve -c in my browser on my pc all the Http requests work which I use HttpClientModule when I already try it on IonicDev App or in the Android studios Emulator I receive an error

{
 “data”: null,
 “status”: 0,
 “config”: {
   “method”: “GET”,
   “transformRequest”: [null], 
   “transformResponse”: [null],
   “Accept”: “ application / json ”,
   “ Content-Type ”:“ application / json ”,
   “ url ”:“

I've also tried creating a proxy in ionic.config.json but I keep throwing the same error

"proxies": [
  {
    "path": "/api",
    "proxyUrl": "http://aqui.com/api"
  }
]
    
asked by Andy Macias 19.11.2018 в 16:35
source

1 answer

1

Point to the IP of the server hosting your web service instead of pointing to localhost. Your ionic client is making requests to himself. When deploying the Ionic application on a device, the client and the server are on separate machines.

    
answered by 19.11.2018 в 17:03