Express.js HTTP请求超时

我想知道是否有人可以告诉我什么时候使用Express的默认HTTP请求超时。

我的意思是:处理一个http请求多less秒后,Express / Node.js服务器closures连接,当浏览器和服务器手动closures连接时?

如何修改单个路由的超时时间? 我想把它设置为15分钟左右的特殊audio转换路线。

非常感谢。

汤姆

req.connection.setTimeout(ms); 可能是一个坏主意,因为多个请求可以通过相同的套接字发送。

尝试连接超时或使用此:

 var errors = require('./errors'); const DEFAULT_TIMEOUT = 10000; const DEFAULT_UPLOAD_TIMEOUT = 2 * 60 * 1000; /* Throws an error after the specified request timeout elapses. Options include: - timeout - uploadTimeout - errorPrototype (the type of Error to throw) */ module.exports = function(options) { //Set options options = options || {}; if(options.timeout == null) options.timeout = DEFAULT_TIMEOUT; if(options.uploadTimeout == null) options.uploadTimeout = DEFAULT_UPLOAD_TIMEOUT; return function(req, res, next) { //timeout is the timeout timeout for this request var tid, timeout = req.is('multipart/form-data') ? options.uploadTimeout : options.timeout; //Add setTimeout and clearTimeout functions req.setTimeout = function(newTimeout) { if(newTimeout != null) timeout = newTimeout; //Reset the timeout for this request req.clearTimeout(); tid = setTimeout(function() { if(options.throwError && !res.finished) { //throw the error var proto = options.error == null ? Error : options.error; next(new proto("Timeout " + req.method + " " + req.url) ); } }, timeout); }; req.clearTimeout = function() { clearTimeout(tid); }; req.getTimeout = function() { return timeout; }; //proxy end to clear the timeout var oldEnd = res.end; res.end = function() { req.clearTimeout(); res.end = oldEnd; return res.end.apply(res, arguments); } //start the timer req.setTimeout(); next(); }; } 

req.connection.setTimeout(ms); 似乎在Node.js中设置HTTP服务器的请求超时。