wrap response in polling call

This commit is contained in:
austinkelsay 2024-11-08 14:12:18 -06:00
parent 393623c4c0
commit 6ac9ba2741
No known key found for this signature in database
GPG Key ID: 44CB4EC6D9F2FA02

View File

@ -78,22 +78,29 @@ export default async function handler(req, res) {
settled: false settled: false
}, { ex: expiry || 86400 }); }, { ex: expiry || 86400 });
// Trigger the polling endpoint without waiting for it // Trigger the polling endpoint
fetch(`${BACKEND_URL}/api/invoices/short-poll`, { try {
headers: { await axios.get(`${BACKEND_URL}/api/invoices/short-poll`, {
'Authorization': PLEBDEVS_API_KEY headers: {
} 'Authorization': PLEBDEVS_API_KEY
}).catch(error => { }
});
res.status(200).json({
invoice,
payment_hash: paymentHashHex,
verify_url: verifyUrl
});
return;
} catch (error) {
console.error('Error triggering polling:', error); console.error('Error triggering polling:', error);
}); // return the response anyway, long running polling will be handled by the cron job
res.status(200).json({
// Return response immediately invoice,
res.status(200).json({ payment_hash: paymentHashHex,
invoice, verify_url: verifyUrl
payment_hash: paymentHashHex, });
verify_url: verifyUrl return;
}); }
return;
} }
// For non-zap requests, send response immediately // For non-zap requests, send response immediately