I'm new at field.
I trying to make pdf generator web application with express.js using html-pdf package.
I have condition on engagement
variable
module.exports =
({rs,periode,engagement,siren,num,rue,codePostal,ville,contratRef,commentaire,nomPrenom,fonction,phone,mail}) => {
const today = new Date();
return `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>
window.onload = function test() {
var o = (document.getElementById('choix1'));
var u = (document.getElementById('choix2'));
if (${ engagement } == "oui") {
o.checked = true;
}else if (${ engagement } == "non") {
u.checked = true
}
}
</script>
When client send data to back end the app crashed and error "cannot set headers after they are sent to the client" in my terminal. how can I resolve this problem ?
Server API code:
app.post('/pdf', (req, res) => {
pdf.create(pdfDocument(req.body), {}).toFile('result.pdf', (err) => {
if(err) { res.send(Promise.reject()); }
res.send(Promise.resolve());
});
});