部署时使用npm包时发生Meteor错误
Meteor error using npm package when deployed
所以我试图使用一个名为html.PDF的NPM包将PDF打印到客户端,在本地一切都很好。我使用了一种迂回的方法来实现这一点,我使用Meteor.call调用一个服务器方法,然后该方法从pdf中获取缓冲输出并将其粘贴到集合中。我使用自动订阅来收听具有当前用户id的新pdf,然后使用包将pdf保存到浏览器。以下重要代码段:
客户端/帮助者.js
Meteor.autosubscribe(function() {
PdfsCollection.find().observe({
added: function(item){
var blob = new Blob([item.pdf], {type: 'application/pdf'});
console.log('new pdf found');
saveAs(blob, 'test.pdf');
PdfsCollection.remove({_id: item._id});
}
});
});
client/templates/quotes/quotes.js:
Template.QuotesEdit.events({
"click #pdf" : function(event, template) {
var html = Blaze.toHTML(Blaze.With(template.data, function() { return Template.QuotePrint; }));
Meteor.call('createPDF', html, Meteor.userId());
}
});
server/pdf.js:
Meteor.methods({
createPDF: function(html, userId) {
var pdf = Meteor.npmRequire('html-pdf');
pdf.create(html).toBuffer(Meteor.bindEnvironment(function(err,buffer) {
PdfsCollection.insert({userId: userId, pdf: buffer});
}));
}
});
导致错误的部分是当我实际调用pdf.create时。有两个错误,在服务器日志中我得到的是:
[Wed Apr 08 2015 03:23:16 GMT+0000 (UTC)] WARNING events.js:72
throw er; // Unhandled 'error' event
^
[Wed Apr 08 2015 03:23:16 GMT+0000 (UTC)] WARNING Error: write EPIPE
at errnoException (net.js:905:11)
at Object.afterWrite (net.js:721:19)
[Wed Apr 08 2015 03:23:16 GMT+0000 (UTC)] ERROR Application crashed with code: 8
[Wed Apr 08 2015 03:23:16 GMT+0000 (UTC)] NOTICE Starting application on port 9000
[Wed Apr 08 2015 03:23:16 GMT+0000 (UTC)] INFO STATUS running -> starting
[Wed Apr 08 2015 03:23:16 GMT+0000 (UTC)] INFO STATUS starting -> running
在浏览器控制台中有这样的:
GET https://ddp--3484-metcrm.meteor.com/sockjs/info?cb=qtrpq640d2 6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 w._start6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 (anonymous function)setTimeout (async)6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 n.delay6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 n.XHRLocalObject6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 X.doXhr6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 (anonymous function)setTimeout (async)6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 n.delay6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 X6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 q6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 T6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:34 a.extend._launchConnection6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:34 a.extend._retryNow6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:3 t.extend.withValue6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:3 n6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:3 e.bindEnvironmentsetTimeout (async)6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:3 t.extend.setTimeout6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:19 t.extend.retryLater6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:34 a.extend._retryLater6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:34 a.extend._lostConnection6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:34 a.extend._launchConnection.t.socket.onclose6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 r.dispatchEvent6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 (anonymous function)setTimeout (async)6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 n.delay6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 T._didClose6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 o._ir.onfinish6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 a.emit6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 X.doXhr.a.onfinish6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 a.emit6f6418a2bd63d77a57cb8a21c5b677d0f83c8d36.js:32 w._start.a.xhr.onreadystatechange
oLxjjRxydCC5AuDig:1 XMLHttpRequest cannot load https://ddp--3484-metcrm.meteor.com/sockjs/info?cb=qtrpq640d2. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://metcrm.meteor.com' is therefore not allowed access. The response had HTTP status code 503.
我现在已经绞尽脑汁3个小时,试图在我的本地服务器上找到它的来源,但在Meteor上没有。这里有两个重要的包:流星黑客:npm(用于在流星中使用npm包)pfafman:filesaver(用于我正在使用的saveas函数)
请提供任何帮助,我们将不胜感激!
我发现这实际上是由在metro.com主机上创建的临时文件的文件权限引起的。我部署到Modulus.io,一切都按预期进行。
相关文章:
- 部署时使用npm包时发生Meteor错误
- Meteor.js Cordova错误:错误白名单拒绝
- Meteor调用404错误
- 在将 Pickadate 与 Meteor 一起使用时,未定义不是函数错误
- 如何将错误消息从 meteor 服务器传递到客户端
- Meteor:使用HTTP.get从客户端访问网站(CORS错误)
- Meteor JS错误”;ReferenceError:X未定义”;
- Meteor错误,未定义手持设备
- Meteor HTTP GET请求-'套接字朝鲜文'错误
- Meteor:排队任务中出现异常:错误:无法执行'removeChild'在'节点':要
- Meteor JavaScript-错误处理
- Meteor上有错误的同步问题
- 如何处理Meteor中未捕获的异常错误
- 错误:找不到模块'开放星云'(Meteor.JS)
- 正在分析Meteor中的错误服务器响应
- 从Meteor呼叫向用户显示相应的错误消息
- Meteor Update集合-未捕获错误:不允许.不受信任的代码只能通过ID更新文档.[403]
- Meteor:未捕获引用错误:未定义帐户
- 使用 Meteor HTTP 在 Spotify API 上请求access_token时不受支持的授权类型错误
- 安装npm模块时发生Meteor错误