我是Meteor的新手,我需要在我的应用程序中创建post end point,这就是为什么我在应用程序中添加了iron:router package
流星加铁:路由器
iron:路由器已成功添加并在我已检查过的包列表中可见
流星列表
Screenshot of package list is attached here 并使用导入它
import { Router } from 'meteor/iron:router';
当我使用这个包来创建终点
Router.route('/testroute').post(function(){
var response;
if(this.request.body.userName === undefined || this.request.body.userPassword === undefined) {
response = {
"error" : true,
"message" : "invalid data"
};
} else {
console.log(" Request Body is : ",this.request.body);
response = {
"error" : false,
"message" : "User added."
}
}
this.response.setHeader('Content-Type','application/json');
this.response.end(JSON.stringify(response));
});
我的代码现在没有编译并给出错误
Exception in callback of async function: TypeError: Cannot read property 'route' of undefined
如果我做错了,请帮助我。提前致谢 :)
import Router from 'meteor/iron:router';
尝试导入没有{}的路由器,因为路由器是从包中导出默认值
我有同样的问题,如果您找到任何解决方案,请告诉我。