You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-16
Original file line number
Diff line number
Diff line change
@@ -23,21 +23,12 @@ If an unsupported encoding is received, it will automatically return a `406` err
23
23
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`.
24
24
25
25
### 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 }`.
console.log(`server listening on ${fastify.server.address().port}`)
40
-
})
28
+
fastify.register(
29
+
require('fastify-compress'),
30
+
{ global:false }
31
+
)
41
32
```
42
33
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.
43
34
@@ -48,7 +39,7 @@ This plugin add a `compress` function to `reply` that accepts a stream or a stri
@@ -61,12 +52,21 @@ fastify.listen(3000, function (err) {
61
52
console.log(`server listening on ${fastify.server.address().port}`)
62
53
})
63
54
```
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
+
```
64
64
### Brotli
65
65
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.
0 commit comments