July 27, 2016

Ionic 2 Proxy while Development with Gulp

From time to time you may need to add a proxy to your Ionic 2 project. It is actually really simple but many articles in the web still refer to the old Ionic 2 build using webpack. Since it is now gulp based and modularized you must use the ionic.config.json file in order to create a new proxy listening on your apps port (pbl. 8100).

Thats it!

 

If you still experience troubles: Try to verify that your proxy works. This can be achieved by installing the handy npm module  http-server. Then set up a server on a different port, call the proxy URL in chrome and see if the request is shown in the logs:

As we can see in the last two lines, the request has gotten trough – proxy definitely works!

 

 

Related Posts

Can Kattwinkel
Developer at thecodecampus </>


5 responses to “Ionic 2 Proxy while Development with Gulp”

  1. Michael Burger says:

    Hi,

    I do exactly that and this is not working for me.

    I create a clean project with ionic2 beta.11 and proxy seems to not work!

  2. Can Kattwinkel says:

    Hello Michael,

    have you checked with the http-server method i mentioned in the article? If yes, please upload the project to GitHub and share the link in order to receive support. 🙂

  3. simon says:

    Does this only work for brwser or android app should also work?

  4. Sonic says:

    it should be “http://someRemoteApi.com/api/v2” instead of “http://someRemoteApi.com/api/v2/”.

  5. Mahesh says:

    Hi Can,

    When I do “proxies”: [
    {
    “path”: “/api/myapp”,
    “proxyUrl”: “http://localhost:13101/”,
    “rejectUnauthorized”: false
    } ]
    and do http.get(“/api/myapp/template”);

    It is not working. But, if I do

    “proxies”: [
    {
    “path”: “/api/myapp/template”,
    “proxyUrl”: “http://localhost:13101/api/myapp/template”,
    “rejectUnauthorized”: false
    } ]

    it is working.

    What am I doing wrong ? my requirement is to map multiple apis like below

    path: “api/myapp/template”
    path: “”api/myapp/template/save”
    path: “”api/myapp/template/{dynamic variable here}”

    Thanks in advance!!

Leave a Reply

Add code to your comment in Markdown syntax.
Like this:
`inline example`

```
code block
example
```

Your email address will not be published.