Proxie no Ionic

Asked

Viewed 27 times

1

I’m having trouble making http requests on Ionic, I saw that one way to bypass 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 I start Ionic it returns to me that the proxie has been added, but when I make the request, Cors slashes me. What am I doing wrong?

1 answer

0

This setting only works by running through ionic serve. That is, if you are going to turn the device (Cordova) 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 can help you:

  1. Native/http: as the very Ionic recommends. However, it will only work by running on the device.

  2. If your application needs to run in the browser as well, or you want to use Angular’s Http for requests, you can use Ionic-Native-http-Connection-backend.

I hope it helps!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.