@goa/compress

Compression Middleware For Goa Apps.

Usage no npm install needed!

<script type="module">
  import goaCompress from 'https://cdn.skypack.dev/@goa/compress';
</script>

README

@goa/compress

npm version

@goa/compress is Compression Middleware For Goa Apps.

yarn add @goa/compress
npm install @goa/compress

Table Of Contents

API

The package is available by importing its default function:

import compress from '@goa/compress'

compress(
  config: !CompressConfig,
): !Middleware

Compression Middleware For Goa Apps.

CompressConfig extends zlib.ZlibOptions

Name Type Description Default
threshold number Minimum response size in bytes to compress. 1024
filter (type?: string) => boolean An optional function that checks the response content type to decide whether to compress. By default, it uses compressible. -
import { aqt } from 'rqt'
import Goa from '@goa/koa'
import compress from '../compile'
import packageJson from '../package'

const goa = new Goa()
goa.use(compress())
goa.use(ctx => {
  ctx.body = packageJson
})

goa.listen(async function() {
  const url = 'http://localhost:' + this.address().port
  const { headers } = await aqt(url)
  console.log(headers)
  this.close()
})
{ vary: 'Accept-Encoding',
  'content-type': 'application/json; charset=utf-8',
  'content-encoding': 'gzip',
  date: 'Thu, 09 Jan 2020 14:35:12 GMT',
  connection: 'close',
  'transfer-encoding': 'chunked' }

Usage Events

This middleware integrates with Idio that collects middleware usage statistics to reward package maintainers. It will emit certain events to bill its usage:

  1. stream: When the compression is applied to stream.
  2. data: When non-stream body is compressed.

The usage is recorded via the ctx.neoluddite context property set by a server such as Idio. In future, more fine-grained usage events might appear.

Copyright & License

GNU Affero General Public License v3.0

Affero GPL means that you're not allowed to use this middleware on the web unless you release the source code for your application. This is a restrictive license which has the purpose of defending Open Source work and its creators.

Please refer to the Idio license agreement for more info on dual-licensing. You're allowed to use this middleware without disclosing the source code if you sign up on neoluddite.dev package reward scheme.

Original work by Jonathan Ong under MIT license found in COPYING.

Art Deco © Art Deco for Idio 2020 Idio Tech Nation Visa Tech Nation Visa Sucks