express icon indicating copy to clipboard operation
express copied to clipboard

How to compress (gzip) responses in express

Open rishav394 opened this issue 5 years ago • 1 comments

I have used compression in my express application like so:

  const compression = require('compression');
  const app = express();
  app.use(compression());

While running locally all my responses are compressed but when running on serverless using sls deploy or sls dev I get net::ERR_CONTENT_DECODING_FAILED 200 I am assuming that serverless cant perform compression but the headers are set by the compression library and thus this error.

I need to compress my responses. I came across this as well but wasn't able to make it work (Nothing was being compressed).

Here is my serverless.yml

org: rishav394
app: my-app
component: express
name: express-compress


inputs:
  src: ./

Any help is appreciated. Thanks.

rishav394 avatar Sep 05 '20 22:09 rishav394

I believe we're gonna have to add the minimumCompressionSize input for that to work, just like the framework. Not 100% sure though 🤔

eahefnawy avatar Sep 15 '20 14:09 eahefnawy