【发布时间】:2018-12-14 01:21:38
【问题描述】:
我正在尝试将数据从节点 js 服务器发送到流星应用程序。在节点 js 应用程序中,我正在这样做:
axios.put('http://localhost:3000/api/project/'+id,{"data" :data, "idExtractor":idExtractor, "version":getVersion()})
其中 data 是我们的服务器给出的 XML 字符串
在我的流星应用程序中,我在 lib/Router.js 文件中的服务器路由上接收到这个,但是当数据太大时,流星服务器给我错误“套接字挂断”和“请求实体太大”。
我在 github 上尝试了 Iron Router 问题的解决方案,在 Router.js 文件中执行以下代码。
if (Meteor.isServer) {
Router.onBeforeAction(Iron.Router.bodyParser.raw({
type: '/',
only: ['creditReferral'],
verify: function(req, res, body){
req.rawBody = body.toString();
},
where: 'server'
}));
Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({
extended: true,
limit : '10mb'
}));
Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({
extended: true,
limit : '10mb'
}),
{ where: 'server'});
}
我尝试将它放在所有路由定义之前,在服务器路由之前,在所有路由之后,我也尝试将它放在启动块中的 server/main.js 中。
我也尝试用这个来改变节点服务器中的这些限制
express.urlencoded({
limit: '10mb',
extended: true,
type: "application/x-www-form-urlencoded"
})
express.json({
limit: '10mb',
strict: false,
type: "application/json"
})
还有这个
app.use(bodyParser.json({ limit: '10mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit :'10mb' }));
但我总是遇到同样的问题,非常感谢所有帮助。
【问题讨论】:
标签: node.js express meteor websocket iron-router