简体   繁体   中英

How to make an API call from one local ionic server to another express local server

So I have two applications running locally; one is ionic2 app running on http://localhost:8041 and another one is express app running on http://localhost:8000 . Now using angular 2 observables when I am making api call with absolute path. For eg From ionic app I making API call to express

getComments(): Observable<any>{
    return this.http.get('http://localhost:8000/comment')
    ......

 }

This is resulting into calling an API at http://localhost:8041/localhost:8000/comment since it is running on local host 8041 port.

How do I handle this problem using angular 2? Also is there a way I can do a proxy calling so that making API call from ionic something like '/comment' will call localhost:8000/comment?

edit ionic.config.json file. add your route to api, then restart server ionic serve

"proxies": [
  {
     "path": "/comment",
     "proxyUrl": "http://localhost:8000/comment"
  }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM