Skip to content

Commit

Permalink
Add a filter to compression to ignore SSE (#210)
Browse files Browse the repository at this point in the history
Server sent events (SSE) don't play nicely with compression.
This commit adds a filter which disables compression for all requests
with Accept: text/event-stream
  • Loading branch information
sigbjorn-myhre authored Oct 24, 2024
1 parent d5d8892 commit 90531c3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ async function startServer() {

const routeUrl = (path: string): string => urlJoin(base.contextPath, path)

app.use(compression())
app.use(compression({
filter: (req: express.Request, res: express.Response) => {
// Don't compress server sent events.
if (req.headers["accept"] === "text/event-stream") {
return false;
}
return compression.filter(req, res);
},
}));

if (cors.origin) {
app.use(corsMiddleware({
Expand Down

0 comments on commit 90531c3

Please sign in to comment.