【发布时间】:2018-05-14 02:16:36
【问题描述】:
我创建了一个服务器端路由(使用 Iron-router)。代码如下:
Router.route( "/apiCall/:username", function(){
var id = this.params.username;
},{ where: "server" } )
.post( function(req, res) {
// If a POST request is made, create the user's profile.
//check for legit request
console.log('post detected')
var userId = Meteor.users.findOne({username : id})._id;
})
.delete( function() {
// If a DELETE request is made, delete the user's profile.
});
这个应用程序在我本地的 3000 端口上运行。现在我创建了另一个在端口 5000 上运行的虚拟应用程序。从虚拟应用程序开始,我正在触发 http.post 请求,然后在 3000 端口上的应用程序上监听它。我使用以下代码通过虚拟应用程序触发 http.post 请求:
apiTest : function(){
console.log('apiTest called')
HTTP.post("http://192.168.1.5:3000/apiCall/testUser", {
data: [
{
"name" : "test"
}
]
}, function (err, res) {
if(!err)
console.log("succesfully posted"); // 4
else
console.log('err',err)
});
return true;
}
但我在回调中收到以下错误:
err { [Error: socket hang up] code: 'ECONNRESET' }
无法弄清楚这里有什么问题。 服务端路由调用成功,但是没有进入 .post() 方法。 使用流星 1.6 版 192.168.1.5是我的ip地址
【问题讨论】:
标签: http meteor connection iron-router