Skip to content

Commit 2ede07a

Browse files
committed
Make maximum wait time configurable, shorten default to 5 minutes, and set server.timeout accordingly. Refs #34.
1 parent 6dfaa96 commit 2ede07a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/invoicing.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import wrap from './lib/promise-wrap'
22

3+
// maximum wait time for long-polling
4+
const maxWait = +process.env.MAX_WAIT || 600
5+
36
module.exports = (app, payListen, model, auth) => {
47
const { newInvoice, fetchInvoice, listInvoices, delExpired } = model
58

9+
app.on('listening', server => server.timeout = maxWait*1000 + 500)
10+
611
app.param('invoice', wrap(async (req, res, next, id) => {
712
req.invoice = await fetchInvoice(req.params.invoice)
813
if (!req.invoice) return res.sendStatus(404)
@@ -23,7 +28,7 @@ module.exports = (app, payListen, model, auth) => {
2328
if (req.invoice.status == 'expired') return res.sendStatus(410)
2429

2530
const expires_in = req.invoice.expires_at - (Date.now()/1000|0)
26-
, timeout = Math.min(+req.query.timeout || 300, expires_in, 1800)
31+
, timeout = Math.min(+req.query.timeout || 300, expires_in, maxWait)
2732
, paid = await payListen.register(req.invoice.id, timeout*1000)
2833

2934
if (paid) res.send(paid)

0 commit comments

Comments
 (0)