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: packages/fetch-router/README.md
+24-8Lines changed: 24 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -874,17 +874,25 @@ let router = createRouter({
874
874
875
875
The middleware is a thin wrapper around the `compress()` response helper that accepts the same options.
876
876
877
-
The middleware applies an additional **Content-Type filter**to only apply compression to appropriate media types (MIME types). By default, this uses the `isCompressibleMediaType(mediaType)` helper to check if the media type is compressible. You can customize this behavior with the `filterMediaType` option, re-using the built-in filter if needed.
877
+
Since this middleware is designed to handle multiple response types at once, the `encodings`, `zlib` and `brotli` options can also be functions that have access to the response before providing a value. For example, to use different encodings for different media types:
878
878
879
-
#### `isCompressibleMediaType(mediaType)`
880
-
881
-
The `isCompressibleMediaType` helper determines whether a media type should be compressed. It returns `true` for:
- Known compressible types from the [mime-db](https://www.npmjs.com/package/mime-db) database (e.g., `application/json`, `text/html`, `text/css`), except those starting with `x-` (experimental) or `vnd.` (vendor-specific).
884
-
- All `text/*` types (e.g., `text/plain`, `text/markdown`)
885
-
- Types with structured data suffixes: `+json`, `+text`, or `+xml` (e.g., `application/vnd.api+json`, `image/svg+xml`)
This helper is primarily intended for use in custom `filterMediaType`functions for the `compression()` middleware:
895
+
The middleware also applies an additional **Content-Type filter** to only apply compression to appropriate media types (MIME types). By default, this uses the `isCompressibleMediaType(mediaType)`helper to check if the media type is compressible. You can customize this behavior with the `filterMediaType`option, re-using the built-in filter if needed.
888
896
889
897
```ts
890
898
import {
@@ -903,6 +911,14 @@ let router = createRouter({
903
911
})
904
912
```
905
913
914
+
The `isCompressibleMediaType` helper determines whether a media type should be compressed. It returns `true` for:
915
+
916
+
- Known compressible types from the [mime-db](https://www.npmjs.com/package/mime-db) database (e.g., `application/json`, `text/html`, `text/css`), except those starting with `x-` (experimental) or `vnd.` (vendor-specific).
917
+
- All `text/*` types (e.g., `text/plain`, `text/markdown`)
918
+
- Types with structured data suffixes: `+json`, `+text`, or `+xml` (e.g., `application/vnd.api+json`, `image/svg+xml`)
919
+
920
+
This helper is primarily intended for use in custom `filterMediaType` functions for the `compression()` middleware.
921
+
906
922
### Testing
907
923
908
924
Testing is straightforward because `fetch-router` uses the standard `fetch()` API:
0 commit comments