Skip to content

Commit 898647a

Browse files
committed
Updated README.md
1 parent 1f5024a commit 898647a

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,12 @@ If an unsupported encoding is received, it will automatically return a `406` err
2323
It automatically defines if a payload should be compressed or not based on its `Content-Type`, if no content type is present, it will assume is `application/json`.
2424

2525
### Global hook
26-
If you want to enable compression to all your routes, pass the option `{ global: true }`.
26+
The global compression hook is enabled by default if you want to disable it, pass the option `{ global: false }`.
2727
```javascript
28-
const fs = require('fs')
29-
const fastify = require('fastify')
30-
31-
fastify.register(require('fastify-compress'), { global: true })
32-
33-
fastify.get('/', (req, reply) => {
34-
reply.send({ hello: 'world' })
35-
})
36-
37-
fastify.listen(3000, function (err) {
38-
if (err) throw err
39-
console.log(`server listening on ${fastify.server.address().port}`)
40-
})
28+
fastify.register(
29+
require('fastify-compress'),
30+
{ global: false }
31+
)
4132
```
4233
Remember that thanks to the Fastify encapsulation model, you can set a global compression, but running it only in a subset of routes is you wrap them inside a plugin.
4334

@@ -48,7 +39,7 @@ This plugin add a `compress` function to `reply` that accepts a stream or a stri
4839
const fs = require('fs')
4940
const fastify = require('fastify')
5041

51-
fastify.register(require('fastify-compress'))
42+
fastify.register(require('fastify-compress'), { global: false })
5243

5344
fastify.get('/', (req, reply) => {
5445
reply
@@ -61,12 +52,21 @@ fastify.listen(3000, function (err) {
6152
console.log(`server listening on ${fastify.server.address().port}`)
6253
})
6354
```
55+
## Options
56+
### Threshold
57+
You can set a custom threshold below which it will not be made compression, default to `1024`.
58+
```javascript
59+
fastify.register(
60+
require('fastify-compress'),
61+
{ threshold: 2048 }
62+
)
63+
```
6464
### Brotli
6565
Brotli compression is not enabled by default, if you need it we recommend to install [`iltorb`](https://www.npmjs.com/package/iltorb) and pass it as option.
6666
```javascript
6767
fastify.register(
6868
require('fastify-compress'),
69-
{ global: true, brotli: require('iltorb') }
69+
{ brotli: require('iltorb') }
7070
)
7171
```
7272

0 commit comments

Comments
 (0)