@goa/compress
v1.2.1
Published
Compression Middleware For Goa Apps.
Downloads
5
Readme
@goa/compress
@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.
- config* !CompressConfig: The config.
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:
stream
: When the compression is applied to stream.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.