https://github.com/idiocc/compress
Compression Middleware For Goa Apps.
https://github.com/idiocc/compress
compress goa gzip idio middleware
Last synced: about 1 year ago
JSON representation
Compression Middleware For Goa Apps.
- Host: GitHub
- URL: https://github.com/idiocc/compress
- Owner: idiocc
- License: other
- Created: 2019-12-23T05:25:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-09T14:36:44.000Z (over 6 years ago)
- Last Synced: 2025-02-15T07:48:59.161Z (over 1 year ago)
- Topics: compress, goa, gzip, idio, middleware
- Language: JavaScript
- Homepage: https://www.idio.cc
- Size: 102 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: COPYING
Awesome Lists containing this project
README
# @goa/compress
[](https://www.npmjs.com/package/@goa/compress)
`@goa/compress` is Compression Middleware For Goa Apps.
```sh
yarn add @goa/compress
npm install @goa/compress
```
## Table Of Contents
- [Table Of Contents](#table-of-contents)
- [API](#api)
- [`compress(config): !Middleware`](#compressconfig-compressconfig-middleware)
* [`CompressConfig`](#type-compressconfig)
- [Usage Events](#usage-events)
- [Copyright & License](#copyright--license)
## API
The package is available by importing its default function:
```js
import compress from '@goa/compress'
```
## compress(
`config: !CompressConfig,`
): !Middleware
Compression Middleware For Goa Apps.
- config* [!CompressConfig](#type-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`. | - |
```js
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()
})
```
```js
{ 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_](https://github.com/idiocc/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.
1. `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](https://github.com/idiocc/idio#copyright--license) 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](https://neoluddite.dev) package reward scheme.
[Original work](https://github.com/koajs/compress) by _Jonathan Ong_ under MIT license found in [COPYING](COPYING).
© Art Deco for Idio 2020
Tech Nation Visa Sucks