From 7976ec7f8aa6bcc58b608a511e4513b97e366ab1 Mon Sep 17 00:00:00 2001 From: Jonathan Cremin Date: Sat, 11 Dec 2021 14:58:56 +0000 Subject: [PATCH] Fix koa-compress memory leak --- app.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index b46674d..dff3196 100644 --- a/app.js +++ b/app.js @@ -21,6 +21,7 @@ import share from './routes/share.js'; import { slack, oauth } from './routes/slack.js'; import errorHandler from './lib/error-handler.js'; import newrelic from 'newrelic'; +import { constants } from 'zlib' const debug = debuglog('combine.fm'); @@ -55,7 +56,19 @@ app.use(errorHandler(Sentry)); app.use(bodyparser()); app.use(cors()); -app.use(compress({ flush: zlib.Z_SYNC_FLUSH })); +app.use(compress({ + filter (content_type) { + return /text/i.test(content_type) + }, + threshold: 2048, + gzip: { + flush: constants.Z_SYNC_FLUSH + }, + deflate: { + flush: constants.Z_SYNC_FLUSH, + }, + br: false + })); app.use(favicon(path.join(__dirname, '/public/assets/images/favicon.png'))); app.use(logger()); app.use(serve('public', { maxage: 31536000000 }));