Juli 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!

 

 

Avatar-Foto

theCodeCampus
Developer at thecodecampus </>

Our knowledge is not simply gained through reading - it is trained, tested and constantly being expanded. Because first and foremost, we are all developers at W11K. The know-how that we acquire here as developers, consultants and information architects flows immediately into our training courses and articles for theCodeCampus.


5 Kommentare zu “Ionic 2 Proxy while Development with Gulp”

  1. Michael Burger sagt:

    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 sagt:

    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 sagt:

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

  4. Sonic sagt:

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

  5. Mahesh sagt:

    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!!

Schreibe einen Kommentar

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

```
code block
example
```

Deine E-Mail-Adresse wird nicht veröffentlicht.