Javascript HTTP触发器上的Azure函数应用程序jsreport不工作
我试图让jsreport在Azure函数应用程序中工作。我已经安装了所需的所有软件包,它们是jsreport core jsreport render jsreport phantom js,它们似乎都工作得很好。我的代码:Javascript HTTP触发器上的Azure函数应用程序jsreport不工作,javascript,node.js,pdf,azure-functions,jsreport,Javascript,Node.js,Pdf,Azure Functions,Jsreport,我试图让jsreport在Azure函数应用程序中工作。我已经安装了所需的所有软件包,它们是jsreport core jsreport render jsreport phantom js,它们似乎都工作得很好。我的代码: module.exports = function (context, req) { context.log('JavaScript HTTP trigger function processed a request.'); if (req.query.content |
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
if (req.query.content || (req.body && req.body.content)) {
var pdf = renderPdf(req.query.content || req.body.content, {})
context.res = {
status: 200,
body: { data: pdf }
};
}
else {
context.res = {
status: 400,
body: "Please pass the content on the query string or in the request body"
};
}
context.done();};
function renderPdf(content, data){
var jsreport = require('jsreport-core')();
var promise = jsreport.init().then(function () {
return jsreport.render({
template: {
content: content,
engine: 'jsrender',
recipe: 'phantom-pdf'
},
data: data
});
});
return Promise.resolve(promise);}
我以这篇文章为例:
我的最终目标是从asp.net核心调用此函数。谢谢你的帮助 您的
renderPdf
函数返回一个承诺,但您没有正确使用该承诺。您不能只将承诺分配给结果主体,而是在中分配主体,然后在中分配主体:
if (req.query.content || (req.body && req.body.content)) {
renderPdf(...).then(pdf => {
context.res = {
status: 200,
body: { data: pdf }
};
context.done();
});
}
else {
context.res = {
status: 400,
body: "Please pass the content on the query string or in the request body"
};
context.done();
}
您的renderPdf
函数返回一个承诺,但您没有正确使用该承诺。您不能只将承诺分配给结果主体,而是在中分配主体,然后在中分配主体:
if (req.query.content || (req.body && req.body.content)) {
renderPdf(...).then(pdf => {
context.res = {
status: 200,
body: { data: pdf }
};
context.done();
});
}
else {
context.res = {
status: 400,
body: "Please pass the content on the query string or in the request body"
};
context.done();
}
那么您面临的问题是什么呢?基本上函数只返回这个{“data”:{}}@Mikhail那么您面临的问题是什么呢?基本上函数只返回这个{“data”:{}@Mikhail