我使用express.js设置了REST服务器。现在,我想向该服务器添加sse。实现此 sse程序包后,出现错误。我知道我收到此错误,何时尝试使用res.send
两次,但我没有。
ERROR: Error: Can't set headers after they are sent. at ServerResponse.OutgoingMessage.setHeader (http.js:690:11) at ServerResponse.header (/home/root/node_modules/express/lib/response.js:718:10) at ServerResponse.send (/home/root/node_modules/express/lib/response.js:163:12) at app.get.str (/home/root/.node_app_slot/main.js:1330:25) at Layer.handle [as handle_request] (/home/root/node_modules/express/lib/router/layer.js:95:5) at next (/home/root/node_modules/express/lib/router/route.js:131:13) at sse (/home/root/node_modules/server-sent-events/index.js:35:2) at Layer.handle [as handle_request] (/home/root/node_modules/express/lib/router/layer.js:95:5) at next (/home/root/node_modules/express/lib/router/route.js:131:13) at Route.dispatch (/home/root/node_modules/express/lib/router/route.js:112:3)
是否有可能我无法在sse函数中使用express方法?例如:
app.get('/events', sse, function(req, res) { res.send('...'); });
此外,我发现这个解决方案,这个。是否可以res.write
在不使用其他软件包的情况下通过该函数或其他方式使用sse ?