# Proxy Problems with Ionic

**URL:** <https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354>\
**Category:** ionic-v3\
**Created:** [February 10, 2016, 11:24am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354 "2016-02-10T11:24:32Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![referral.works](https://avatars.discourse-cdn.com/v4/letter/r/f08c70/32.png) [@referral.works](https://forum.ionicframework.com/u/referral.works)\
**Post date:** [September 17, 2016, 11:28pm UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/23 "2016-09-17T23:28:40Z")

</div>

Hi All,

I’m having trouble accessing google api’s at the moment on device (ironically). Kind of reverse to what problem many of you have. Because when you run ionic run android -l it uses the IP of the phone, 192.168.0.1.x as the base instead of localhost (as on my laptop environment)- googles api security does not accept any requests when I test on my phone.

Any suggestions?

I’m trying a way around by creating a node proxy on my server and relaying packets, though for authentication I’m still not sure how this would work. Hoping for an easier solution!

Appreciate any time and help, as I’m still Learning.

Thanks,  
Kieran

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [September 26, 2016, 10:41pm UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/24 "2016-09-26T22:41:35Z")

</div>

Here is a sample project with proxy setup and small server returning static data.

> **[mhartington/V2Proxy](https://github.com/mhartington/V2Proxy)**
>
> Contribute to V2Proxy development by creating an account on GitHub.

Please note, that proxies **only** work during `ionic serve`.

Also note, `ionic run -lc` DOES NOT work with recent changes in cordova/OS updates. The livereload request will be blocked.

---

<div class="post-metadata">

**Author:** ![vaibsVB](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vaibsvb/32/102515_2.png) [@vaibsVB](https://forum.ionicframework.com/u/vaibsVB)\
**Post date:** [September 27, 2016, 9:32am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/25 "2016-09-27T09:32:58Z")

</div>

@mhartington Thanks for providing a sample project on `proxy` problem with `ionic-2`.

I need help in my case, I have to hit multiple URL for performing different actions/operations.

for example:  
To Authenticate - [https://my-domain.com/web/session/authenticate](https://my-domain.com/web/session/authenticate)  
To get session info - [https://my-domain.com/web/session/get\_session\_info](https://my-domain.com/web/session/get_session_info)  
To search read - [https://my-domain.com/web/dataset/search\_read](https://my-domain.com/web/dataset/search_read)

To Read - [https://my-domain.com/web/dataset/call\_kw/project.task/create](https://my-domain.com/web/dataset/call_kw/project.task/create)  
To Read - [https://my-domain.com/web/dataset/call\_kw/project.task/read](https://my-domain.com/web/dataset/call_kw/project.task/read)  
To Write - [https://my-domain.com/web/dataset/call\_kw/project.task/write](https://my-domain.com/web/dataset/call_kw/project.task/write)  
To Delete - [https://my-domain.com/web/dataset/call\_kw/project.task/unlink](https://my-domain.com/web/dataset/call_kw/project.task/unlink)

`https://my-domain.com/web/session/` and `https://my-domain.com/web/dataset/call_kw/` this remains common in many of the places.  
The changing part is `project.task/write` or `project.task/create` or `authenticate`, etc.

Can you please help how can I handle this in proxy? I’m not able to make it for multiple URLs.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![CanKattw](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@CanKattw](https://forum.ionicframework.com/u/CanKattw)\
**Post date:** [September 28, 2016, 9:50am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/26 "2016-09-28T09:50:38Z")

</div>

There is no need to proxy every URL. Simply add a proxy for your Domain.

{  
“path”: “/api”,  
“proxyUrl”: " [https://my-domain.com/](https://my-domain.com/)"  
}

Your calls in your app should then go to /api/web/sessions/authenticate.

It might be helpful for someone who is new to proxys to test with node module “http-server”. Just install with npm i -g http-server. It will only create a server at any port u want. Then any request is logged to the console. So you can play around with the paths until you see that you have the correct settings. Then change to your actual url ( before you use e.g. [http://localhost:8080](http://localhost:8080) as proxy url).

See [http://blog.thecodecampus.de/ionic-2-proxy-development/](http://blog.thecodecampus.de/ionic-2-proxy-development/) for more details about Proxys in Ionic 2 and how to test them with http-server. 🙂

---

<div class="post-metadata">

**Author:** ![vaibsVB](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vaibsvb/32/102515_2.png) [@vaibsVB](https://forum.ionicframework.com/u/vaibsVB)\
**Post date:** [September 28, 2016, 10:03am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/27 "2016-09-28T10:03:20Z")

</div>

@CanKattw Thanks for your valuable input. 🙂  
I’ll check and let you know.

Another thing I want to ask is [quote=“CanKattw, post:26, topic:43354”]  
“path”: “/api”, _\<== over here_  
[/quote]

at the path is there need to provide `/api`? Because in my URL, there is no `/path` anywhere.  
Is there mandatory?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![CanKattw](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@CanKattw](https://forum.ionicframework.com/u/CanKattw)\
**Post date:** [September 28, 2016, 10:20am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/28 "2016-09-28T10:20:56Z")

</div>

“path”: “/api”, -\> you call this while ionic serve e.g in your http gets:

```
http.get('/api/web/sessions/authenticate')

```

which will be resolved to the proxyUrl.

---

<div class="post-metadata">

**Author:** ![vaibsVB](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/vaibsvb/32/102515_2.png) [@vaibsVB](https://forum.ionicframework.com/u/vaibsVB)\
**Post date:** [September 28, 2016, 10:23am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/29 "2016-09-28T10:23:58Z")

</div>

Ohh… Now I got it 😅  
@CanKattw Thanks for your prompt reply.

---

<div class="post-metadata">

**Author:** ![dericeira](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dericeira/32/102842_2.png) [@dericeira](https://forum.ionicframework.com/u/dericeira)\
**Post date:** [October 21, 2016, 5:45pm UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/30 "2016-10-21T17:45:22Z")

</div>

This solution is not working anymore. ☹  
I cannot make my requests.

---

<div class="post-metadata">

**Author:** ![dericeira](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dericeira/32/102842_2.png) [@dericeira](https://forum.ionicframework.com/u/dericeira)\
**Post date:** [October 24, 2016, 3:38pm UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/31 "2016-10-24T15:38:24Z")

</div>

Guys, I solved my problem installing a chrome plugin: “Allow-Control-Allow-Origin \*” (yeah, It’s the plugin name).

---

<div class="post-metadata">

**Author:** ![MadhavBitra](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@MadhavBitra](https://forum.ionicframework.com/u/MadhavBitra)\
**Post date:** [December 19, 2016, 4:18pm UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/32 "2016-12-19T16:18:37Z")

</div>

> [@kattasrinu](#):
>
> “proxies”: [  
> {  
> “path”: “/api”,  
> “proxyUrl”: “[http://xxxxxxxxx](http://xxxxxxxxx)”  
> }  
> ]  
> }
> 
> this.http.post(‘/api’+“username=”+username+“&password=”+password)  
> .map(res =\>res.json())  
> .subscribe(data =\> {  
> this.data = data;  
> })

Hi Srinu, Thanks This has worked for me.

---

<div class="post-metadata">

**Author:** ![Arains](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arains/32/107023_2.png) [@Arains](https://forum.ionicframework.com/u/Arains)\
**Post date:** [March 22, 2017, 5:59pm UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/33 "2017-03-22T17:59:34Z")

</div>

I’m probably missing something, but here’s what I’m doing and I’m getting a 404:

ionic.config.js

```
    {
      "name": "AppName",
      "app_id": "",
      "v2": true,
      "typescript": true,
      "proxies": [
        {
          "path": "/forecast/",
          "proxyUrl": "https://api.darksky.net/forecast/"
        }
      ]
    }

```

home.ts

```
this.http.get('/forecast/'+this.key+'/'+this.latitude+','+this.longitude+'?units=ca&exclude=alerts,flags,madis-stations,daily,minutely,hourly')`

```

Error in console:

```
error_handler.js:47 EXCEPTION: Response with status: 404 Not Found for URL: http://localhost:8100/forecast/myKeyShowCorrectly/43.669579,-79.38863?units=ca&exclude=alerts,flags,madis-stations,daily,minutely,hourly 

```

If I add the correct URL path ([https://api.darksky.net/forecast/](https://api.darksky.net/forecast/)) to the combined string, it works in Postman. So for some reason the proxy isn’t passing [https://api.darksky.net/forecast/](https://api.darksky.net/forecast/) correctly to the called URL.

Have at me! What am I missing?

Thank you.

---

<div class="post-metadata">

**Author:** ![mbpro](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mbpro/32/108143_2.png) [@mbpro](https://forum.ionicframework.com/u/mbpro)\
**Post date:** [April 4, 2017, 12:04am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/34 "2017-04-04T00:04:59Z")

</div>

Same problem here.

Using `ionic serve` works fine but `ionic run android` just fails because `/api` does not exist.

How are we supposed to deal with this? Some kind of NODE\_ENV-hot-loading-path-changing-base-url?

---

<div class="post-metadata">

**Author:** ![FrancoisIonic](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/francoisionic/32/106767_2.png) [@FrancoisIonic](https://forum.ionicframework.com/u/FrancoisIonic)\
**Post date:** [April 11, 2017, 7:33am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/35 "2017-04-11T07:33:57Z")

</div>

The API is not made to work on a localhist basis.  
If you work wil a CUSTOM datasource, it’ss mage for your + items.daasource.

I Wont.

---

<div class="post-metadata">

**Author:** ![rubenmgar](https://avatars.discourse-cdn.com/v4/letter/r/c67d28/32.png) [@rubenmgar](https://forum.ionicframework.com/u/rubenmgar)\
**Post date:** [May 31, 2017, 4:33pm UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/36 "2017-05-31T16:33:30Z")

</div>

Hi, same problem here. If I create proxy, it works with ionic serve, but does’nt work with ionic run, because “file:///api/sales.php Failed to load resource: net::ERR\_FILE\_NOT\_FOUND”. Any ideas? Thanks!

---

<div class="post-metadata">

**Author:** ![jeffreyCarre](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jeffreycarre/32/110768_2.png) [@jeffreyCarre](https://forum.ionicframework.com/u/jeffreyCarre)\
**Post date:** [June 5, 2017, 4:30am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/37 "2017-06-05T04:30:36Z")

</div>

Did you restart ionic serve?

---

<div class="post-metadata">

**Author:** ![picardfolefack](https://avatars.discourse-cdn.com/v4/letter/p/9de0a6/32.png) [@picardfolefack](https://forum.ionicframework.com/u/picardfolefack)\
**Post date:** [July 28, 2017, 4:41am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/38 "2017-07-28T04:41:12Z")

</div>

This worked for me. Thanks for saving me hours!

---

<div class="post-metadata">

**Author:** ![alvinchettiar](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@alvinchettiar](https://forum.ionicframework.com/u/alvinchettiar)\
**Post date:** [October 16, 2017, 6:49pm UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/39 "2017-10-16T18:49:50Z")

</div>

Hey Guys,

Few more details about the above implementation.

{  
“name”: “myApp”,  
“app\_id”: “”,  
“v2”: true,  
“proxies”: [  
{  
“path”: “/api”,  
“proxyUrl”: “[http://xxxxxxxxx](http://xxxxxxxxx)”  
}  
]  
}

The above code given by kattasrinu is perfectly fine except that the ‘proxyUrl’ should contain /api at the end. So the updated code would look like this.

{  
“name”: “myApp”,  
“app\_id”: “”,  
“v2”: true,  
“proxies”: [  
{  
“path”: “/api”,  
“proxyUrl”: “[http://xxxxxxxxx/api](http://xxxxxxxxx/api)”  
}  
]  
}

If we don’t add /api, it wont work and would give a CORSE error.

Thank you kattasrinu for the great piece of code.

---

<div class="post-metadata">

**Author:** ![supportabalit](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@supportabalit](https://forum.ionicframework.com/u/supportabalit)\
**Post date:** [October 30, 2017, 10:04am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/40 "2017-10-30T10:04:30Z")

</div>

Oh I love u so much! That was my problem 😅

---

<div class="post-metadata">

**Author:** ![AMHZ](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/amhz/32/111978_2.png) [@AMHZ](https://forum.ionicframework.com/u/AMHZ)\
**Post date:** [November 5, 2017, 3:59pm UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/41 "2017-11-05T15:59:08Z")

</div>

Saved me from 1 hour searching

---

<div class="post-metadata">

**Author:** ![Sharanagouda](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sharanagouda](https://forum.ionicframework.com/u/Sharanagouda)\
**Post date:** [November 8, 2017, 7:45am UTC](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354/42 "2017-11-08T07:45:17Z")

</div>

[ERROR] The config file (.\ionic.config.json) is not valid JSON format. after modifying

I validated my code in [https://jsonlint.com/](https://jsonlint.com/)

here is my code

```auto
{
  "name": "eventsPro",
  "app_id": "3bf0810b",
  "type": "ionic-angular",
  "integrations": {
    "cordova": {}
  },
  "v2": true,
  "typescript": true,
  "proxies": [
    {
      "path": "/app",
      "proxyUrl": "https://www.bizcentra.com"
    }
  ]
}

```

[Previous page](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354.md?page=1)

[Next page](https://forum.ionicframework.com/t/proxy-problems-with-ionic/43354.md?page=3)
