I am sending data to my server that creates a pdf file based from the request, which is being created fine but I cant get the file to be sent back to the client. I am using React to submit the form
handleSubmit(event) {
event.preventDefault();
var body = {
id: this.state.id,
text: this.state.text
}
fetch('http://localhost:5000/pdf', {
method: 'POST',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json'
},
}).then(function(file) {
window.open(file.url);
});
}
Its opening http://localhost:5000/pdf, but since I don't have a GET route for it, nothing gets download. This is my POST route
router.post('/pdf', async function(req, res) {
var makePdf = require('./file-create/pdf.js');
makePdf(req, res);
});
and the file is being returned as pdfDoc.pipe(res);
I cant just use a GET route because I can't get data sent in with that way, how can I get this file to get sent to the client?