Som*_*ens 86
express
考虑到你在问题中的日志,我假设你正在使用.关键是timeout
在服务器上设置属性(以下将超时设置为一秒,使用您想要的任何值):
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
server.timeout = 1000;
Run Code Online (Sandbox Code Playgroud)
如果您不使用express并且仅使用vanilla节点,原则是相同的.以下内容不会返回数据:
var http = require('http');
var server = http.createServer(function (req, res) {
setTimeout(function() {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}, 200);
}).listen(1337, '127.0.0.1');
server.timeout = 20;
console.log('Server running at http://127.0.0.1:1337/');
Run Code Online (Sandbox Code Playgroud)
Lee*_*Lee 37
试试这个:
var options = {
url: 'http://url',
timeout: 120000
}
request(options, function(err, resp, body) {});
Run Code Online (Sandbox Code Playgroud)
有关其他选项,请参阅请求文档.
Iva*_*_ug 11
您可以为整个服务器全局设置超时:
var server = app.listen();
server.setTimeout(500000);
Run Code Online (Sandbox Code Playgroud)
或仅针对特定路线:
app.post('/xxx', function (req, res) {
req.setTimeout(500000);
});
Run Code Online (Sandbox Code Playgroud)
小智 10
对于特定请求,可以将timeOut设置为0,直到我们从DB或其他服务器获得回复为止才会超时
request.setTimeout(0)
Run Code Online (Sandbox Code Playgroud)
小智 5
对于那些在 中配置的bin/www
,只需在 http 服务器创建后添加 timeout 参数。
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces
*/
server.listen(port);
server.timeout=yourValueInMillisecond
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
110145 次 |
最近记录: |