How to do proxy to avoid CORS for ionic2 apps?

This is not a solution. Disabling CORS is like removing the headlight from your car when it breaks. Cors do exist for a reason. While development use a proxy to your API. It is very simple, just add 2 lines to your config.

ionic.config.json:

{
  "name": "client",
  "app_id": "",
  "v2": true,
  "typescript": true,
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "http://someRemoteApi.com/api/v2/"
    }
  ]
}

See this blog post for detailed information and an example on how to verify that the proxy works:

1 Like