express-sse
express-sse copied to clipboard
DeprecationWarning: OutgoingMessage.flush is deprecated.
Using the latest version of Node, I'm getting the following warning when a client is connected to the SSE endpoint and a server event is sent:
(node:16688) [DEP0001] DeprecationWarning: OutgoingMessage.flush is deprecated. Use flushHeaders instead.
I think this is likely related to commit 96723a006760e93e6bb2a5fbad53da744951c586, which added res.flush()
after the message is sent.
I've removed the res.flush()
when I'm using it, and have instead set the compression
module to ignore SSE. Not sure if it's worth removing it here and documenting that instead?
app.use(
compression({
filter: (req, res) =>
!res.getHeaders()["content-type"].includes("text/event-stream"),
})
);
@cooper667, the more general solution would be to include no-transform
in the Cache-Control
header. Not only does compression
respect that directive but any proxy between client and server, too. Unfortunately, this package hardcodes the header value to no-cache
.
In recent node, express-sse
doesn't work at all for this reason.
same problem here. seems incompatible. node just crashes
Looks like there is already a pull request out there to handle no-transform
. https://github.com/dpskvn/express-sse/pull/31 Now, we just need to fix the flush()
.
It seems that there is not so much activity here right now. For people that are still looking for a solution for the res.flush() problem (TypeError: res.flush is not a function) and are not using the compression middleware for express.js. You can create a simple middleware function for express that adds the function.
The following piece of code could maybe help some people:
app.use(function (req, res, next) {
res.flush = function () { /* Do nothing */ }
next();
})
This adds the empty function to res object and express-sse will not crash anymore. You can also just downgrade your express-sse package in package.json
and set it fixed to 0.5.1 for now. The other solution is to start using another package. But mostly this requires modifying existing code.
This pull request would solve the problem i think. https://github.com/dpskvn/express-sse/pull/29/commits/2f8f08da7cb90fa27fd54d723688fa81aa610316
I hope this helps some people.
@wiegvlieg , to reduce the workaround affect area, we can do it like this:
app.get('/sse', (req, res, next) => {
res.flush = () => {};
next();
}, sse.init);
It seems that there is not so much activity here right now. For people that are still looking for a solution for the res.flush() problem (TypeError: res.flush is not a function) and are not using the compression middleware for express.js. You can create a simple middleware function for express that adds the function.
The following piece of code could maybe help some people:
app.use(function (req, res, next) { res.flush = function () { /* Do nothing */ } next(); })
This adds the empty function to res object and express-sse will not crash anymore. You can also just downgrade your express-sse package in
package.json
and set it fixed to 0.5.1 for now. The other solution is to start using another package. But mostly this requires modifying existing code.This pull request would solve the problem i think. 2f8f08d
I hope this helps some people.
this helped me thanks a lot