mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +00:00
Use fetch again, change timeout
This commit is contained in:
parent
6ac9ba2741
commit
83c614f276
@ -14,7 +14,7 @@ export default async function handler(req, res) {
|
|||||||
try {
|
try {
|
||||||
// Poll for 120 seconds maximum
|
// Poll for 120 seconds maximum
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
const timeoutDuration = 120000; // 120 seconds in milliseconds
|
const timeoutDuration = 30000; // 30 seconds in milliseconds
|
||||||
|
|
||||||
while (Date.now() - startTime < timeoutDuration) {
|
while (Date.now() - startTime < timeoutDuration) {
|
||||||
const pollResponse = await axios.get(`${BACKEND_URL}/api/invoices/polling`, {
|
const pollResponse = await axios.get(`${BACKEND_URL}/api/invoices/polling`, {
|
||||||
|
@ -78,22 +78,16 @@ export default async function handler(req, res) {
|
|||||||
settled: false
|
settled: false
|
||||||
}, { ex: expiry || 86400 });
|
}, { ex: expiry || 86400 });
|
||||||
|
|
||||||
// Trigger the polling endpoint
|
// Trigger the polling endpoint without waiting for it
|
||||||
try {
|
fetch(`${BACKEND_URL}/api/lightning-address/short-poll`, {
|
||||||
await axios.get(`${BACKEND_URL}/api/invoices/short-poll`, {
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': PLEBDEVS_API_KEY
|
'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
|
});
|
||||||
|
|
||||||
|
// Return response immediately
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
invoice,
|
invoice,
|
||||||
payment_hash: paymentHashHex,
|
payment_hash: paymentHashHex,
|
||||||
@ -101,7 +95,6 @@ export default async function handler(req, res) {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// For non-zap requests, send response immediately
|
// For non-zap requests, send response immediately
|
||||||
res.status(200).json({ invoice, payment_hash: paymentHashHex });
|
res.status(200).json({ invoice, payment_hash: paymentHashHex });
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
],
|
],
|
||||||
"functions": {
|
"functions": {
|
||||||
"src/pages/api/invoices/short-poll.js": {
|
"src/pages/api/invoices/short-poll.js": {
|
||||||
"maxDuration": 120
|
"maxDuration": 60
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user