我在流星和简单中使用restivus:json-routes作为中间件。
在中间件功能中,一旦收到文件数据,集合上的插入方法就会失败。
错误:Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
JsonRoutes.Middleware.use((request, response, next) => {
if (request.url === "/upload" && request.method === "POST") {
let fileInfo, data;
request.on("data", (chunks) => {
data += chunks;
console.log("data in ");
});
request.on("end", () => {
res = someCollection.insert({test: 'value'});
console.log(res);
if (res) next();
});
}
else {
next();
}
});