Node.js:Express.js设置保持活动状态

时间:2020-04-17 13:58:10

标签: javascript node.js express

在express.js Web服务器中设置keep alive的正确方法是什么?

我找到了声音的例子。

示例n。 1

var express = require('express');
var app = express();
var server = app.listen(5001);

server.on('connection', function(socket) {
  socket.setTimeout(30 * 1000);
});

示例n。 2

var express = require('express');
var app = express();
var server = app.listen(5001);
server.keepAliveTimeout = 30 * 1000;

1 个答案:

答案 0 :(得分:1)

server.headersTimeout设置为大于server.keepAliveTimeout的值。 (check this solution for a similar issuethis page

示例代码:

var express = require('express');
var app = express();
var server = app.listen(5001);
server.keepAliveTimeout = 30 * 1000;
server.headersTimeout = 35 * 1000;