I'm trying out the connect-timeout module.
I've tried hitting a simple route from the browser
var timeout = require('connect-timeout');
app.use(timeout('1s'));
app.use(haltOnTimedout);
app.get('/timeout', function (req, res) {
for (var i = 0; i < 1111211111; i++) {}
res.send('d')
})
function haltOnTimedout(req, res, next){
if (!req.timedout) next();
}
But I'm always getting back in the browser (I thought the timeout would prevent it). Anything I'm not getting here?
The problem is that your for loop executes in under a second. Try this:
In this example, the route wont return a response until the 5 second timeout function executes. However, the connect-timeout middleware will halt execution before then.