Proxy Problems with Ionic

Hello,

I have the same issue, and the fefelegal’s link is not the solution (as the problem is in the browser and not in my device)

Regards,
Peekmo

1 Like

same with me.
http://localhost:8100/apiaddress from browser does not work. It looks the server do not act on ionic.project. Even if i change the name of ionic.project, ionic serve does not complain with it.

You have to set proxies in ionic.config.js, i.e:
module.exports = { proxies: [{ "path": "/twitter/", "proxyUrl": "https://api.twitter.com/" }], }

It was big help. With your configuration to js file, proxy start working. Thank you.

Now that ionic.config.js is no longer being used in the latest beta, do you know where this code would go?

In ionic2 ionic.config.json is working for me am using beta version only. And this is my proxy:

{
  "name": "myApp",
  "app_id": "",
  "v2": true,
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "http://xxxxxxxxx"
    }  
  ]
}
  this.http.post('/api'+"username="+username+"&password="+password)
    .map(res =>res.json())
    .subscribe(data => {
      this.data = data;
    })
9 Likes

I need to make proxy work in ionic 2. I used to have it set at ionic.config.js and it was working well. Now ionic.config.js is deprecated and I don’t know how to use proxy anymore.

@evandrojr The answer is right above your question:

This works quite fine for basic proxying. But the headers seem to be ignored (e.g. for basic authentication). Is there an option to pass these through as well?

1 Like

It doesn’t seem so but you could open a new issue or feature request.

Hi @kattasrinu,

i configured out my ionic.config.json file as you described

{
    "name": "web-client-ionic2",
    "app_id": "",
    "v2": true,
    "typescript": true,
    "proxies": [
        {
            "path": "/api",
            "proxyUrl": "http://192.168.1.1"
        }
    ]
}

and my store is this

import { Http, Headers } from '@angular/http';
...
var httpCall = this.http
               .post('/api/v1/users/log  in', JSON.stringify(body), {headers: headers});
               //.map(res => res.json());

return httpCall;

But I always get 404, it seems proxy configuration is not working, I’m using ionic2 beta.11

some ideas?

Same issue here, using ionic2 beta.10

{
  "name": "",
  "app_id": "",
  "v2": true,
  "typescript": true,
  "proxies": [
    {
      "path": "/pdf_file",
      "proxyUrl": "http://xxxxxxxxx/pdf"
    }
  ]
}

shows 404 file:///pdf_file/pdf-test.pdf not found

I don’t know what I have done but after a while the proxy works fine!
Did you stop and restart ionic serve after change proxy settings?

Hello, I’m starting in ionic2 and I have the same problem, below you can see my configuration

ionic.config.json:

{
“name”: “bt-v2”,
“app_id”: “”,
“v2”: true,
“typescript”: true,
“proxies”: [
{
“path”: “/parse”,
“proxyUrl”: “http://appbt.metasix.solutions/parse
},
{
“path”: “/feed”,
“proxyUrl”: “http://appbt.metasix.solutions/node
}
]
}
----------------------------
Provider:
load(){
if(this.data){
return Promise.resolve(this.data);
}
return new Promise((resolve, reject) => {
//https://randomuser.me/api/?results=10
this.http.get(’/feed’)
.map(res => res.json())
.subscribe(data => {
this.data = data.results;
resolve(this.data);
}, err => reject(err));
});
}

Unless I am really missing something this should work but no way it is not. I have configured a proxy as stated above in my [ionic.config.json] but still no luck with POST requests.

{
  "name": "*******",
  "app_id": "******",
  "v2": true,
  "typescript": true,
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "http://localhost:8080"
    }
  ]
}

I want to add this api works flawlessly from command line using curl.

@kees.schouten Were you able to pass the headers? I have similar issue, I got the proxy working but looks like header information seems to be ignored.

No I did not. But ended up using Chrome with the following startup variables (OSX):

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security --user-data-dir ~/Library/Application Support/Google/Chrome/Default &

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

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

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.

3 Likes

@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
To get session info - https://my-domain.com/web/session/get_session_info
To search read - https://my-domain.com/web/dataset/search_read

To Read - https://my-domain.com/web/dataset/call_kw/project.task/create
To 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
To Delete - 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.