Proxie on Ionic

1

I'm having trouble doing http requests on Ionic, I saw that one way to circumvent CORS is by using proxies.

I tried something like:

ionic.config.json:

{
  "name": "appIonic",
  "integrations": {
    "cordova": {}
  },
  "proxies": [
    {
      "path": "/loginnovo",
      "proxyUrl": "https://loginsiteapixx/loginnovo"
    }],
  "type": "ionic-angular"
}

At my service:

basepath = "";

  constructor(public _http: HttpClient, private _platform: Platform) {

    if(this._platform.is("cordova")){
      this.basepath = "https://loginsiteapixx"
    }

  }


  public login(credenciais){
    return this._http.post(this.basepath + '/loginnovo',
    {email: credenciais.email, password: credenciais.password}, 
    {observe: 'response'}) 
    .pipe(
      map((response) => ({data: response.body, status: response.status}))
    )}

When Ionic starts it returns me that the proxie was added, but when I make the request, the cors bars me. What am I doing wrong?

    
asked by anonymous 07.08.2018 / 18:48

1 answer

0

This setting only works by ionic serve . That is to say, if it is rotated in the device (cord) it will not work.

If you have control over the backend, it is interesting to implement the CORS filter on the server side. If this is not possible, there are 2 plugins that can help you:

  • Native / http : Like ionic recommends . However, it will only work by running the device.

  • If your application needs to run in the browser either, or you want to use the Angular Http for requests, you can use ionic-native-http-connection-backend .

  • I hope it helps!

        
    17.08.2018 / 19:32