【发布时间】:2014-06-03 14:25:45
【问题描述】:
所以我的 express js 节点应用程序中有一个事件流。这是一个概述:
app.get('/eventstream', function(req, res){
req.socket.setTimeout(Infinity);
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
});
res.write('/n');
req.on('close', function(){
console.log('connection closed');
});
}
在我的本地开发机器上,从命令行运行
node app.js
它工作正常,当我在浏览器中关闭标签时会打印出“连接已关闭”。 但是,当在我的服务器上运行时,在带有乘客的 Apache 下,它不会打印出任何消息 - 服务器似乎没有触发“关闭”事件。我正在使用此事件从我的活跃用户数中删除。有什么想法吗?
干杯, 丹
【问题讨论】:
标签: javascript node.js express passenger server-sent-events