From 6ac9ba27417d0fc1d9e429e612582d3b2a52fa4a Mon Sep 17 00:00:00 2001 From: austinkelsay Date: Fri, 8 Nov 2024 14:12:18 -0600 Subject: [PATCH] wrap response in polling call --- src/pages/api/lightning-address/lnd.js | 37 +++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/pages/api/lightning-address/lnd.js b/src/pages/api/lightning-address/lnd.js index aae76c8..912d0ae 100644 --- a/src/pages/api/lightning-address/lnd.js +++ b/src/pages/api/lightning-address/lnd.js @@ -78,22 +78,29 @@ export default async function handler(req, res) { settled: false }, { ex: expiry || 86400 }); - // Trigger the polling endpoint without waiting for it - fetch(`${BACKEND_URL}/api/invoices/short-poll`, { - headers: { - 'Authorization': PLEBDEVS_API_KEY - } - }).catch(error => { + // Trigger the polling endpoint + try { + await axios.get(`${BACKEND_URL}/api/invoices/short-poll`, { + headers: { + 'Authorization': PLEBDEVS_API_KEY + } + }); + res.status(200).json({ + invoice, + payment_hash: paymentHashHex, + verify_url: verifyUrl + }); + return; + } catch (error) { console.error('Error triggering polling:', error); - }); - - // Return response immediately - res.status(200).json({ - invoice, - payment_hash: paymentHashHex, - verify_url: verifyUrl - }); - return; + // return the response anyway, long running polling will be handled by the cron job + res.status(200).json({ + invoice, + payment_hash: paymentHashHex, + verify_url: verifyUrl + }); + return; + } } // For non-zap requests, send response immediately