当我们使用 fs.write 而不是 fs.render 并希望在输出中包含页眉和页脚时。我尝试使用包含,它给出了一个错误。
像这样的行不起作用 -> const head = require('../views/partials/production-header.html');
async function readInFile(theFile) {
return await fs.readFile(path + theFile)
}
router.get('/:qry', function(req, res) {
readInFile('/views/partials/production-header.html').then(data => {
let head = data.toString()
readInFile('/views/partials/production-footer.html').then(data => {
let foot = data.toString()
display_page(head, foot)
})
})
})
function display_page(head,foot,filter) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(head);
res.write(q);
res.write(foot);
res.end();
}
以上工作,但似乎并不是最好的方法