需要减少对expressjs路由的超时时间(Need to reduce the timeout p

2019-07-18 10:30发布

在expressjs是有办法,我可以设置每路的超时限制。

我有可能需要30-45秒的过程中的一些路线(A大量的任务)

然后其他路线,如果需要超过5秒,我希望它超时。

我想我问的是有没有全局设置超时限制的请求的方式,是有办法单独做它的路线。

Answer 1:

使用内置的连接超时中间件:

http://www.senchalabs.org/connect/timeout.html

var connectTimeout = require('connect-timeout');

var timeout = connectTimeout({ time: 10000 });
var longTimeout = connectTimeout({ time: 45000 });

app.use(timeout); // you can set a global timeout value
app.get('/some/route', longTimeout, yourHandler); // or you can set per-route timeouts


文章来源: Need to reduce the timeout period for a route in expressjs