简体   繁体   English

部署时使用npm包出现流星错误

[英]Meteor error using npm package when deployed

So I was attempting to print PDF's to the client using a NPM package called html-pdf, locally everything works beautifully. 因此,我尝试使用名为html-pdf的NPM软件包将PDF打印到客户端,在本地一切正常。 I used a round about way to do this, I use Meteor.call to call a server method that then takes the buffered output from the pdf and sticks it in a collection. 我使用了一种方法来做到这一点,我使用Meteor.call调用服务器方法,然后从pdf中获取缓冲的输出并将其粘贴在集合中。 I use an autosubscribe to listen for a new pdf with the current user id then use a package to save the pdf to the browser. 我使用自动订阅功能以当前用户ID收听新的pdf,然后使用一个软件包将pdf保存到浏览器。 important code pieces below: 以下是重要的代码段:

client/helpers.js 客户机/ helpers.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: 客户端/模板/报价/ 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: 服务器/ 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});
    }));
  }
});

The part that is causing the error is when I actually call pdf.create. 导致错误的部分是当我实际调用pdf.create时。 There are two errors, in the server log I get this: 在服务器日志中有两个错误,我得到以下信息:

[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

and in the browser console there is this: 在浏览器控制台中是这样的:

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.

I have now racked my brains for 3 hours trying to find the source of this working on my local server but not on Meteor. 现在,我花了3个小时动脑筋,试图找到在本地服务器上而不是在Meteor上工作的源。 The two important packages here are: meteorhacks:npm (for using npm packages in meteor) pfafman:filesaver (for the saveas function I am using) 这里有两个重要的软件包:meteorhacks:npm(用于在流星中使用npm软件包)pfafman:filesaver(用于我正在使用的saveas函数)

Please any help is appreciated! 请任何帮助表示赞赏!

I found that this was actually caused by file permissions for the temp file that was being created on meteor.com hosting. 我发现这实际上是由在meteor.com托管上创建的临时文件的文件权限引起的。 I deployed to Modulus.io and all is working as expected. 我部署到Modulus.io,并且一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM