Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTTP触发器上的Azure函数应用程序jsreport不工作_Javascript_Node.js_Pdf_Azure Functions_Jsreport - Fatal编程技术网

Javascript HTTP触发器上的Azure函数应用程序jsreport不工作

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 |

我试图让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 || (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