我正在研究一个在集合上创建报告器的应用程序,然后在铁路由器控制器的服务器上,我将此代码用于通过webshot生成我的pdf,然后我通过电子邮件发送pdf。
就像localhost上的一个魅力,但在服务器上一直告诉我504网关超时
这是我的routes.js文件中的代码
AccountOverrides@1.0.0/SuiteScript/Account.Model.js
...
return SCModel.extend({
name: 'Account'
, register: function (user_data)
{
// Check if there is already a user/customer with this email address
// The below function will crash the script because
// the script cannot access the 'customer' table
var emailDulicates = nlapiSearchRecord('customer', null,
new nlobjSearchFilter('email', null, 'is', ''+user_data.email));
if (emailDulicates && emailDulicates.length > 0) {
Application.sendError({"Email already taken."});
return false;
}
... continue on to register user
}
});
我已经尝试手动设置phantomPath,没有它,在主机上安装幻像并使用通过mup自动安装的幻像,增加渲染延迟甚至10秒!我还可以做些什么?
更新26/04/2018
发现我的应用实际上是在这个目录中创建pdf /bundle/bundle/programs/server/nameofpdf.pdf
Meteor.methods({'sendMail': sendMail});
Router.route('generatePDF', {
path: '/reportes/generate-pdf/:_id', // example route with _id param
where: 'server',
action: function() {
// Get invoice ID parameter
var id = this.params._id;
var tipo = Reportes.findOne(id).tipo;
var fecha = Reportes.findOne(id).Fechadeservicio;
// Setting name for our generated PDF
var fileName = fecha+"-"+tipo+"-reporte_.pdf";
// Load NPM packages
var webshot = Npm.require('webshot');
var fs = Npm.require('fs');
var Future = Npm.require('fibers/future');
var fut = new Future();
// Set path to your route here - Meteor.absoluteUrl() is your root url ("http://localhost:3000/")
var url = Meteor.absoluteUrl('reportepdf/'+id); // Meteor.absoluteUrl('path/to/your/route');
var options = {
renderDelay: 3000,
paperSize: {
format: "Letter",
orientation: "portrait",
margin: "1cm",
phantomPath: "/usr/local/share/phantomjs-1.9.8-linux-x86_64/bin/phantomjs"
} //papersize
}; //options
// Magic happens here...
webshot(url, fileName, options, function(err) {
if (err) {
return console.log(err);
} else {
fs.readFile(fileName, function (error,data) {
if (error) {
return console.log(err);
}
fs.unlinkSync(fileName);
fut.return(data);
});
}
});
let pdfData = fut.wait();
let base64String = new Buffer(pdfData).toString('base64');
sendMail({
to: "nubestra@gmail.com",
from: "israel@nubestra.com",
subject: "prueba",
nombrepdf: fileName,
attachment: base64String
});
this.response.writeHead(302, {
'Location': "/"
});
this.response.end();
//this.response.writeHead(200, {'Content-Type': 'application/pdf',"Content-Disposition": "attachment; filename=" + fileName});
//this.response.end(fut.wait());
}
});
未删除临时文件
也没有解释为什么本地工作和服务器上卡住了。