https://github.com/kanongil/brok
Brotli encoder and decoder for hapi.js
https://github.com/kanongil/brok
brotli brotli-encoder hapi hapi-plugin javascript node
Last synced: 5 months ago
JSON representation
Brotli encoder and decoder for hapi.js
- Host: GitHub
- URL: https://github.com/kanongil/brok
- Owner: kanongil
- License: other
- Created: 2016-08-22T13:30:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-25T09:35:16.000Z (about 1 year ago)
- Last Synced: 2024-04-14T05:57:01.328Z (about 1 year ago)
- Topics: brotli, brotli-encoder, hapi, hapi-plugin, javascript, node
- Language: JavaScript
- Size: 92.8 KB
- Stars: 15
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# brok
Brotli encoder and decoder for hapi.js.
[](https://github.com/kanongil/brok/actions/workflows/ci.yaml)
Lead Maintainer - [Gil Pedersen](https://github.com/kanongil)
## Install
```sh
npm install brok
```## Example
### Registration
Registration with custom quality default:
```js
'use strict';const Hapi = require('@hapi/hapi');
const Brok = require('brok');const server = new Hapi.Server({ port: 3000, compression: { minBytes: 1 } });
const provision = async () => {
server.route({
method: 'GET',
path: '/fetch',
handler() {return 'ok';
}
});await server.register({
plugin: Brok,
options: {
compress: { quality: 3 }
}
});await server.start();
console.log('Server running at:', server.info.uri);
};provision();
```## Usage
Once registered, **brok** enables the server to negotiate and handle the `"br"` encoding for
compressible responses and uploads.### Registration options
**brok** accepts the following registration options:
- `compress` - compression settings.
Set to `false` to disable response compression using brotli.
- `quality` - used to adjust compression speed vs quality from 0 to 11.
Defaults to `5`.
- `mode` - compression mode.
Available values:
- `'generic'` - default compression mode. Default value.
- `'text'` - optimize for UTF-8 formatted text input.
- `decompress` - if `true`, also register the encoding for decompressing incoming payloads.
Defaults to `false`.### Compression options
Route specific settings can be set using `br` object in the `compression` config. Eg.
```js
server.route({
method: 'GET',
path: '/text',
options: {
handler() {return 'hello!';
},
compression: {
br: { mode: 'text' }
}
}
});
```