I am setting up a website for a desktop app I created. The website provides users a way to also download the app after a payment via Stripe. In order to do the proper verification before allowing the app to download, I am trying to respond to a POST request with downloading the file. I am seeing no errors but the browser is not downloading the file.
Server.js
app.post('/pay', jsonParser, async (req, res) => {
// ...
// Stripe payment verification
// ...
if (intent.status === 'succeeded') {
console.log('downloading');
res.setHeader( "Content-Disposition", `attachment; filename=${path.join(__dirname, '..', 'app', 'test.txt')}` );
res.download(path.join(__dirname, '..', 'app', 'test.txt'), (error) => {
if (error) throw error;
});
}
}
Checkout.js
fetch(
'/pay',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}
)
.then(handleServerResponse)