Use fetch again, change timeout

This commit is contained in:
austinkelsay 2024-11-08 14:17:20 -06:00
parent 6ac9ba2741
commit 83c614f276
No known key found for this signature in database
GPG Key ID: 44CB4EC6D9F2FA02
3 changed files with 17 additions and 24 deletions

View File

@ -14,7 +14,7 @@ export default async function handler(req, res) {
try {
// Poll for 120 seconds maximum
const startTime = Date.now();
const timeoutDuration = 120000; // 120 seconds in milliseconds
const timeoutDuration = 30000; // 30 seconds in milliseconds
while (Date.now() - startTime < timeoutDuration) {
const pollResponse = await axios.get(`${BACKEND_URL}/api/invoices/polling`, {

View File

@ -78,29 +78,22 @@ export default async function handler(req, res) {
settled: false
}, { ex: expiry || 86400 });
// 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) {
// Trigger the polling endpoint without waiting for it
fetch(`${BACKEND_URL}/api/lightning-address/short-poll`, {
headers: {
'Authorization': PLEBDEVS_API_KEY
}
}).catch(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({
invoice,
payment_hash: paymentHashHex,
verify_url: verifyUrl
});
return;
}
});
// Return response immediately
res.status(200).json({
invoice,
payment_hash: paymentHashHex,
verify_url: verifyUrl
});
return;
}
// For non-zap requests, send response immediately

View File

@ -12,7 +12,7 @@
],
"functions": {
"src/pages/api/invoices/short-poll.js": {
"maxDuration": 120
"maxDuration": 60
}
}
}