gpt4 book ai didi

node.js - jsreport 简单报告 - 无输出

转载 作者:太空宇宙 更新时间:2023-11-04 00:55:24 26 4
gpt4 key购买 nike

我正在尝试输出我的第一个简单报告,以便我可以开始使用 jsreport。这是我的代码,但它没有输出任何内容。

它在端口 8080 上运行,没有错误。当我访问本地主机 url 时,它就坐在那里。

var http = require('http');

function handleRequest ( request, response ) {
require('jsreport').render('<h1>Hello world</h1>').then(function ( out ) {
out.result.pipe(resp);
});
}

var server = http.createServer(handleRequest);

server.listen(8080, function(){
console.log("Server listening on: http://localhost:%s", 8080);
});

我可能没有正确提供内容,但是他们的文档非常缺乏,无法在您自己的应用程序中实现。

最佳答案

jsreport.render 返回 promise并且你应该正确处理它的失败

require('jsreport').render('<h1>Hello world</h1>').then(function ( out ) {
out.result.pipe(resp);
}).catch(function(e) {
console.log(e);
response.end(e.message);
});

将其应用到您的代码中时,我收到一个错误,指出您在 out.result.pipe(resp); 中存在拼写错误。它应该是 out.result.pipe(response);

关于node.js - jsreport 简单报告 - 无输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30089367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com