我有一个Ionic 2应用程序,当我使用ionic serve
时,带有代理i用户进行开发。在我的配置文件中,所有这些都很好地处理了:
"proxies": [
{
"path": "/apiv2/",
"proxyUrl": "https://myapilink.com/apiv2/"
}
]
和我的离子提供商:
constructor(public http: Http) {
this.API_URL = "/apiv2";
this.data = {};
}
call(action, entity, params){
return new Promise(resolve => {
let link = this.API_URL;
let data = JSON.stringify({action: action, entity: entity, params: params});
this.http.post(link, data)
.map(res => res.json())
.subscribe(data => {
this.data = data;
resolve(this.data);
}, error => {
console.log(error);
});
});
}
当我使用ionic serve
运行离子项目时,我可以看到添加了代理:
[09:54:50] Proxy added:/apiv2/ => https://myapilink.com/apiv2/
但是,当我运行应用程序时,当API调用时,在我的网络日志中,我只有500个错误:
POST http://localhost:8100/apiv2/ 500 (Internal Server Error)
但是,当离子服务器正在运行时,如果我继续使用chrome并输入此URL:http://localhost:8100/apiv2/
,则我的API结果是我的JSON返回,因此进行了重定向。我不明白它来自哪里
预先感谢您的任何帮助
github中有一些指南:https://github.com/ionic-team/ionic-cli#service-proxies。也许在ionic.config.json中,您应该像这样:
"proxies": [
{
"path": "/apiv2/",
"proxyUrl": "https://localhost:8100/apiv2/"
}
]