[英]Http request from node server to Strapi throws error "econnrefused"
[英]$http request in ionic app to a simple node server throws “statusText”: “” error
我已经删除了对骨骼的 $http 请求,但它仍然失败,没有有用的错误消息。 在我的 Angular 工厂中,我有:
var url = "http://localhost:3000";
var deferred = $q.defer();
$http.get(url)
.then(function (success) {
deferred.resolve(success)
})
.catch(function (err) {
deferred.reject(err)
})
return deferred.promise;
在我的节点路由中,我有:
router.get('/', function(req, res, next) {
res.json({test: 'hi from node index.js'})
});
我在 ionic 应用程序中收到的完整错误是:
{
"data": null,
"status": -1,
"config": {
"method": "GET",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http://localhost:3000",
"headers": {
"Accept": "application/json, text/plain, */*"
}
},
"statusText": ""
我试图在我的节点服务器中捕获错误并且我收到
TypeError: Cannot read property 'type' of undefined
我在我的节点 app.js 中禁用了 cors。 我试图与套接字建立连接,但仍然没有任何运气。 我正在使用 ionic run 运行我的 ionic 应用程序。
任何帮助将不胜感激。 谢谢。
解决方案:自然,设备有它自己的本地主机,所以当我从我的 ionic 应用程序发送 $http.get 请求时,它不会将它发送到运行节点服务器的同一个本地主机。 解决方案是针对您部署的服务器或本地机器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.