[英]How to make an API call from one local ionic server to another express local server
因此,我有兩個在本地運行的應用程序; 一個是在http:// localhost:8041上運行的ionic2應用程序,另一個是在http:// localhost:8000上運行的express應用程序。 現在在使用絕對路徑進行api調用時使用angular 2 observables。 例如,從離子應用程序,我進行API調用來表達
getComments(): Observable<any>{
return this.http.get('http://localhost:8000/comment')
......
}
由於它在本地主機8041端口上運行,因此導致在http:// localhost:8041 / localhost:8000 / comment處調用API。
如何使用角度2處理此問題? 還有一種方法可以執行代理調用,以便從離子(例如'/ comment')進行API調用將調用localhost:8000 / comment?
編輯ionic.config.json
文件。 將您的路由添加到api,然后重新啟動服務器ionic serve
"proxies": [
{
"path": "/comment",
"proxyUrl": "http://localhost:8000/comment"
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.