fastify 4.27.0 → 5.0.0-aplha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/.markdownlint-cli2.yaml +1 -1
  2. package/README.md +2 -4
  3. package/build/build-validation.js +3 -3
  4. package/docs/Guides/Delay-Accepting-Requests.md +3 -3
  5. package/docs/Guides/Migration-Guide-V5.md +20 -0
  6. package/docs/Reference/ContentTypeParser.md +8 -1
  7. package/docs/Reference/Decorators.md +2 -2
  8. package/docs/Reference/Errors.md +8 -2
  9. package/docs/Reference/Logging.md +5 -5
  10. package/docs/Reference/Request.md +5 -1
  11. package/docs/Reference/Routes.md +19 -23
  12. package/docs/Reference/Server.md +14 -53
  13. package/docs/Reference/Warnings.md +0 -4
  14. package/fastify.d.ts +2 -1
  15. package/fastify.js +36 -6
  16. package/lib/configValidator.js +92 -75
  17. package/lib/contentTypeParser.js +54 -88
  18. package/lib/errors.js +27 -6
  19. package/lib/handleRequest.js +15 -22
  20. package/lib/httpMethods.js +34 -18
  21. package/lib/logger.js +24 -6
  22. package/lib/pluginUtils.js +3 -3
  23. package/lib/request.js +32 -11
  24. package/lib/route.js +6 -31
  25. package/lib/server.js +5 -106
  26. package/lib/warnings.js +24 -17
  27. package/package.json +29 -28
  28. package/test/async-await.test.js +46 -2
  29. package/test/check.test.js +225 -0
  30. package/test/content-parser.test.js +69 -117
  31. package/test/custom-parser.1.test.js +40 -1
  32. package/test/delete.test.js +21 -1
  33. package/test/findRoute.test.js +16 -0
  34. package/test/genReqId.test.js +9 -0
  35. package/test/get.test.js +28 -0
  36. package/test/has-route.test.js +1 -1
  37. package/test/helper.js +1 -5
  38. package/test/http2/constraint.test.js +22 -1
  39. package/test/http2/plain.test.js +21 -6
  40. package/test/http2/secure.test.js +12 -1
  41. package/test/https/https.test.js +57 -0
  42. package/test/internals/errors.test.js +47 -17
  43. package/test/internals/initialConfig.test.js +5 -5
  44. package/test/internals/logger.test.js +31 -2
  45. package/test/internals/request.test.js +13 -11
  46. package/test/logger/instantiation.test.js +8 -8
  47. package/test/logger/logging.test.js +4 -4
  48. package/test/logger/options.test.js +102 -21
  49. package/test/logger/response.test.js +6 -6
  50. package/test/method-missing.test.js +24 -0
  51. package/test/plugin.4.test.js +27 -31
  52. package/test/route-shorthand.test.js +60 -0
  53. package/test/server.test.js +16 -0
  54. package/test/stream.2.test.js +1 -1
  55. package/test/stream.5.test.js +2 -2
  56. package/test/trust-proxy.test.js +33 -27
  57. package/test/types/errors.test-d.ts +0 -2
  58. package/test/types/fastify.test-d.ts +1 -1
  59. package/test/types/instance.test-d.ts +3 -49
  60. package/test/types/logger.test-d.ts +42 -4
  61. package/test/types/register.test-d.ts +1 -1
  62. package/test/types/request.test-d.ts +3 -1
  63. package/test/types/route.test-d.ts +6 -2
  64. package/test/url-rewriting.test.js +3 -2
  65. package/test/useSemicolonDelimiter.test.js +3 -6
  66. package/test/versioned-routes.test.js +1 -1
  67. package/types/instance.d.ts +12 -28
  68. package/types/logger.d.ts +1 -1
  69. package/types/request.d.ts +2 -0
  70. package/test/default-route.test.js +0 -88
  71. package/test/listen.deprecated.test.js +0 -229
  72. package/test/unsupported-httpversion.test.js +0 -31
@@ -7,7 +7,7 @@ config:
7
7
  MD013:
8
8
  line_length: 80
9
9
  code_block_line_length: 120
10
- headers: false
10
+ headings: false
11
11
  tables: false
12
12
  strict: false
13
13
  stern: false
package/README.md CHANGED
@@ -46,10 +46,8 @@ developer experience with the least overhead and a powerful plugin architecture.
46
46
  It is inspired by Hapi and Express and as far as we know, it is one of the
47
47
  fastest web frameworks in town.
48
48
 
49
- The `main` branch refers to the Fastify `v4` release. Check out the
50
- [`v3.x` branch](https://github.com/fastify/fastify/tree/3.x) for `v3`.
51
-
52
-
49
+ The `main` branch refers to the Fastify `v5` release, which is not released/LTS yet.
50
+ Check out the [`4.x` branch](https://github.com/fastify/fastify/tree/4.x) for `v4`.
53
51
 
54
52
  ### Table of Contents
55
53
 
@@ -38,11 +38,11 @@ const defaultInitOptions = {
38
38
  onProtoPoisoning: 'error',
39
39
  onConstructorPoisoning: 'error',
40
40
  pluginTimeout: 10000,
41
- requestIdHeader: 'request-id',
41
+ requestIdHeader: false,
42
42
  requestIdLogLabel: 'reqId',
43
43
  http2SessionTimeout: 72000, // 72 seconds
44
44
  exposeHeadRoutes: true,
45
- useSemicolonDelimiter: true
45
+ useSemicolonDelimiter: false
46
46
  }
47
47
 
48
48
  const schema = {
@@ -98,7 +98,7 @@ const schema = {
98
98
  onProtoPoisoning: { type: 'string', default: defaultInitOptions.onProtoPoisoning },
99
99
  onConstructorPoisoning: { type: 'string', default: defaultInitOptions.onConstructorPoisoning },
100
100
  pluginTimeout: { type: 'integer', default: defaultInitOptions.pluginTimeout },
101
- requestIdHeader: { anyOf: [{ enum: [false] }, { type: 'string' }], default: defaultInitOptions.requestIdHeader },
101
+ requestIdHeader: { anyOf: [{ type: 'boolean' }, { type: 'string' }], default: defaultInitOptions.requestIdHeader },
102
102
  requestIdLogLabel: { type: 'string', default: defaultInitOptions.requestIdLogLabel },
103
103
  http2SessionTimeout: { type: 'integer', default: defaultInitOptions.http2SessionTimeout },
104
104
  exposeHeadRoutes: { type: 'boolean', default: defaultInitOptions.exposeHeadRoutes },
@@ -103,7 +103,7 @@ server.get('/v1*', async function (request, reply) {
103
103
  }
104
104
  })
105
105
 
106
- server.decorate('magicKey', null)
106
+ server.decorate('magicKey')
107
107
 
108
108
  server.listen({ port: '1234' }, () => {
109
109
  provider.thirdPartyMagicKeyGenerator(USUAL_WAIT_TIME_MS)
@@ -303,7 +303,7 @@ async function setup(fastify) {
303
303
  fastify.server.on('listening', doMagic)
304
304
 
305
305
  // Set up the placeholder for the magicKey
306
- fastify.decorate('magicKey', null)
306
+ fastify.decorate('magicKey')
307
307
 
308
308
  // Our magic -- important to make sure errors are handled. Beware of async
309
309
  // functions outside `try/catch` blocks
@@ -406,7 +406,7 @@ https://nodejs.org/api/net.html#event-listening). We use that to reach out to
406
406
  our provider as soon as possible, with the `doMagic` function.
407
407
 
408
408
  ```js
409
- fastify.decorate('magicKey', null)
409
+ fastify.decorate('magicKey')
410
410
  ```
411
411
 
412
412
  The `magicKey` decoration is also part of the plugin now. We initialize it with
@@ -0,0 +1,20 @@
1
+ # V5 Migration Guide
2
+
3
+ This guide is intended to help with migration from Fastify v4 to v5.
4
+
5
+ Before migrating to v5, please ensure that you have fixed all deprecation
6
+ warnings from v4. All v4 deprecations have been removed and they will no longer
7
+ work after upgrading.
8
+
9
+ ## Breaking Changes
10
+
11
+ ### `useSemicolonDelimiter` false by default
12
+
13
+ Starting with v5, Fastify instances will no longer default to supporting the use
14
+ of semicolon delimiters in the query string as they did in v4.
15
+ This is due to it being non-standard
16
+ behavior and not adhering to [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986#section-3.4).
17
+
18
+ If you still wish to use semicolons as delimiters, you can do so by
19
+ setting `useSemicolonDelimiter: true` in the server configuration.
20
+
@@ -29,6 +29,13 @@ is given in the content-type header. If it is not given, the
29
29
  [catch-all](#catch-all) parser is not executed as with `POST`, `PUT` and
30
30
  `PATCH`, but the payload is simply not parsed.
31
31
 
32
+ > ## ⚠ Security Notice
33
+ > When using with RegExp to detect `Content-Type`, you should beware of
34
+ > how to properly detect the `Content-Type`. For example, if you need
35
+ > `application/*`, you should use `/^application\/([\w-]+);?/` to match the
36
+ > [essence MIME type](https://mimesniff.spec.whatwg.org/#mime-type-miscellaneous)
37
+ > only.
38
+
32
39
  ### Usage
33
40
  ```js
34
41
  fastify.addContentTypeParser('application/jsoff', function (request, payload, done) {
@@ -52,7 +59,7 @@ fastify.addContentTypeParser('application/jsoff', async function (request, paylo
52
59
  })
53
60
 
54
61
  // Handle all content types that matches RegExp
55
- fastify.addContentTypeParser(/^image\/.*/, function (request, payload, done) {
62
+ fastify.addContentTypeParser(/^image\/([\w-]+);?/, function (request, payload, done) {
56
63
  imageParser(payload, function (err, body) {
57
64
  done(err, body)
58
65
  })
@@ -193,7 +193,7 @@ hook](./Hooks.md#onrequest). Example:
193
193
  const fp = require('fastify-plugin')
194
194
 
195
195
  async function myPlugin (app) {
196
- app.decorateRequest('foo', null)
196
+ app.decorateRequest('foo')
197
197
  app.addHook('onRequest', async (req, reply) => {
198
198
  req.foo = { bar: 42 }
199
199
  })
@@ -236,7 +236,7 @@ incoming request in the [`'onRequest'` hook](./Hooks.md#onrequest). Example:
236
236
  const fp = require('fastify-plugin')
237
237
 
238
238
  async function myPlugin (app) {
239
- app.decorateRequest('foo', null)
239
+ app.decorateRequest('foo')
240
240
  app.addHook('onRequest', async (req, reply) => {
241
241
  req.foo = { bar: 42 }
242
242
  })
@@ -44,6 +44,9 @@
44
44
  - [FST_ERR_HOOK_TIMEOUT](#fst_err_hook_timeout)
45
45
  - [FST_ERR_LOG_INVALID_DESTINATION](#fst_err_log_invalid_destination)
46
46
  - [FST_ERR_LOG_INVALID_LOGGER](#fst_err_log_invalid_logger)
47
+ - [FST_ERR_LOG_INVALID_LOGGER_INSTANCE](#fst_err_log_invalid_logger_instance)
48
+ - [FST_ERR_LOG_INVALID_LOGGER_CONFIG](#fst_err_log_invalid_logger_config)
49
+ - [FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED](#fst_err_log_logger_and_logger_instance_provided)
47
50
  - [FST_ERR_REP_INVALID_PAYLOAD_TYPE](#fst_err_rep_invalid_payload_type)
48
51
  - [FST_ERR_REP_RESPONSE_BODY_CONSUMED](#fst_err_rep_response_body_consumed)
49
52
  - [FST_ERR_REP_ALREADY_SENT](#fst_err_rep_already_sent)
@@ -70,7 +73,6 @@
70
73
  - [FST_ERR_DUPLICATED_ROUTE](#fst_err_duplicated_route)
71
74
  - [FST_ERR_BAD_URL](#fst_err_bad_url)
72
75
  - [FST_ERR_ASYNC_CONSTRAINT](#fst_err_async_constraint)
73
- - [FST_ERR_DEFAULT_ROUTE_INVALID_TYPE](#fst_err_default_route_invalid_type)
74
76
  - [FST_ERR_INVALID_URL](#fst_err_invalid_url)
75
77
  - [FST_ERR_ROUTE_OPTIONS_NOT_OBJ](#fst_err_route_options_not_obj)
76
78
  - [FST_ERR_ROUTE_DUPLICATED_HANDLER](#fst_err_route_duplicated_handler)
@@ -90,6 +92,7 @@
90
92
  - [FST_ERR_PARENT_PLUGIN_BOOTED](#fst_err_parent_plugin_booted)
91
93
  - [FST_ERR_PLUGIN_TIMEOUT](#fst_err_plugin_timeout)
92
94
  - [FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE](#fst_err_plugin_not_present_in_instance)
95
+ - [FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER](#fst_err_plugin_invalid_async_handler)
93
96
  - [FST_ERR_VALIDATION](#fst_err_validation)
94
97
  - [FST_ERR_LISTEN_OPTIONS_INVALID](#fst_err_listen_options_invalid)
95
98
  - [FST_ERR_ERROR_HANDLER_NOT_FN](#fst_err_error_handler_not_fn)
@@ -313,6 +316,9 @@ Below is a table with all the error codes that Fastify uses.
313
316
  | <a id="fst_err_hook_timeout">FST_ERR_HOOK_TIMEOUT</a> | A callback for a hook timed out. | Increase the timeout for the hook. | [#3106](https://github.com/fastify/fastify/pull/3106) |
314
317
  | <a id="fst_err_log_invalid_destination">FST_ERR_LOG_INVALID_DESTINATION</a> | The logger does not accept the specified destination. | Use a `'stream'` or a `'file'` as the destination. | [#1168](https://github.com/fastify/fastify/pull/1168) |
315
318
  | <a id="fst_err_log_invalid_logger">FST_ERR_LOG_INVALID_LOGGER</a> | The logger should have all these methods: `'info'`, `'error'`, `'debug'`, `'fatal'`, `'warn'`, `'trace'`, `'child'`. | Use a logger with all the required methods. | [#4520](https://github.com/fastify/fastify/pull/4520) |
319
+ | <a id="fst_err_log_invalid_logger_instance">FST_ERR_LOG_INVALID_LOGGER_INSTANCE</a> | The `loggerInstance` only accepts a logger instance, not a configuration object. | To pass a configuration object, use `'logger'` instead. | [#5020](https://github.com/fastify/fastify/pull/5020) |
320
+ | <a id="fst_err_log_invalid_logger_config">FST_ERR_LOG_INVALID_LOGGER_CONFIG</a> | The logger option only accepts a configuration object, not a logger instance. | To pass an instance, use `'loggerInstance'` instead. | [#5020](https://github.com/fastify/fastify/pull/5020) |
321
+ | <a id="fst_err_log_logger_and_logger_instance_provided">FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED</a> | You cannot provide both `'logger'` and `'loggerInstance'`. | Please provide only one option. | [#5020](https://github.com/fastify/fastify/pull/5020) |
316
322
  | <a id="fst_err_rep_invalid_payload_type">FST_ERR_REP_INVALID_PAYLOAD_TYPE</a> | Reply payload can be either a `string` or a `Buffer`. | Use a `string` or a `Buffer` for the payload. | [#1168](https://github.com/fastify/fastify/pull/1168) |
317
323
  | <a id="fst_err_rep_response_body_consumed">FST_ERR_REP_RESPONSE_BODY_CONSUMED</a> | Using `Response` as reply payload, but the body is being consumed. | Make sure you don't consume the `Response.body` | [#5286](https://github.com/fastify/fastify/pull/5286) |
318
324
  | <a id="fst_err_rep_already_sent">FST_ERR_REP_ALREADY_SENT</a> | A response was already sent. | - | [#1336](https://github.com/fastify/fastify/pull/1336) |
@@ -339,7 +345,6 @@ Below is a table with all the error codes that Fastify uses.
339
345
  | <a id="fst_err_duplicated_route">FST_ERR_DUPLICATED_ROUTE</a> | The HTTP method already has a registered controller for that URL. | Use a different URL or register the controller for another HTTP method. | [#2954](https://github.com/fastify/fastify/pull/2954) |
340
346
  | <a id="fst_err_bad_url">FST_ERR_BAD_URL</a> | The router received an invalid URL. | Use a valid URL. | [#2106](https://github.com/fastify/fastify/pull/2106) |
341
347
  | <a id="fst_err_async_constraint">FST_ERR_ASYNC_CONSTRAINT</a> | The router received an error when using asynchronous constraints. | - | [#4323](https://github.com/fastify/fastify/pull/4323) |
342
- | <a id="fst_err_default_route_invalid_type">FST_ERR_DEFAULT_ROUTE_INVALID_TYPE</a> | The `defaultRoute` type should be a function. | Use a function for the `defaultRoute`. | [#2733](https://github.com/fastify/fastify/pull/2733) |
343
348
  | <a id="fst_err_invalid_url">FST_ERR_INVALID_URL</a> | URL must be a string. | Use a string for the URL. | [#3653](https://github.com/fastify/fastify/pull/3653) |
344
349
  | <a id="fst_err_route_options_not_obj">FST_ERR_ROUTE_OPTIONS_NOT_OBJ</a> | Options for the route must be an object. | Use an object for the route options. | [#4554](https://github.com/fastify/fastify/pull/4554) |
345
350
  | <a id="fst_err_route_duplicated_handler">FST_ERR_ROUTE_DUPLICATED_HANDLER</a> | Duplicate handler for the route is not allowed. | Use a different handler. | [#4554](https://github.com/fastify/fastify/pull/4554) |
@@ -359,6 +364,7 @@ Below is a table with all the error codes that Fastify uses.
359
364
  | <a id="fst_err_parent_plugin_booted">FST_ERR_PARENT_PLUGIN_BOOTED</a> | Impossible to load plugin because the parent (mapped directly from `avvio`) | - | [#3106](https://github.com/fastify/fastify/pull/3106) |
360
365
  | <a id="fst_err_plugin_timeout">FST_ERR_PLUGIN_TIMEOUT</a> | Plugin did not start in time. | Increase the timeout for the plugin. | [#3106](https://github.com/fastify/fastify/pull/3106) |
361
366
  | <a id="fst_err_plugin_not_present_in_instance">FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE</a> | The decorator is not present in the instance. | - | [#4554](https://github.com/fastify/fastify/pull/4554) |
367
+ | <a id="fst_err_plugin_invalid_async_handler">FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER</a> | The plugin being registered mixes async and callback styles. | - | [#5141](https://github.com/fastify/fastify/pull/5141) |
362
368
  | <a id="fst_err_validation">FST_ERR_VALIDATION</a> | The Request failed the payload validation. | Check the request payload. | [#4824](https://github.com/fastify/fastify/pull/4824) |
363
369
  | <a id="fst_err_listen_options_invalid">FST_ERR_LISTEN_OPTIONS_INVALID</a> | Invalid listen options. | Check the listen options. | [#4886](https://github.com/fastify/fastify/pull/4886) |
364
370
  | <a id="fst_err_error_handler_not_fn">FST_ERR_ERROR_HANDLER_NOT_FN</a> | Error Handler must be a function | Provide a function to `setErrorHandler`. | [#5317](https://github.com/fastify/fastify/pull/5317) |
@@ -98,10 +98,10 @@ const fastify = require('fastify')({
98
98
  <a id="logging-request-id"></a>
99
99
 
100
100
  By default, Fastify adds an ID to every request for easier tracking. If the
101
- "request-id" header is present its value is used, otherwise a new incremental ID
102
- is generated. See Fastify Factory
103
- [`requestIdHeader`](./Server.md#factory-request-id-header) and Fastify Factory
104
- [`genReqId`](./Server.md#genreqid) for customization options.
101
+ requestIdHeader-option is set and the corresponding header is present than
102
+ its value is used, otherwise a new incremental ID is generated. See Fastify
103
+ Factory [`requestIdHeader`](./Server.md#factory-request-id-header) and Fastify
104
+ Factory [`genReqId`](./Server.md#genreqid) for customization options.
105
105
 
106
106
  The default logger is configured with a set of standard serializers that
107
107
  serialize objects with `req`, `res`, and `err` properties. The object received
@@ -243,7 +243,7 @@ const fastify = Fastify({
243
243
  method: request.method,
244
244
  url: request.url,
245
245
  headers: request.headers,
246
- hostname: request.hostname,
246
+ host: request.host,
247
247
  remoteAddress: request.ip,
248
248
  remotePort: request.socket.remotePort
249
249
  }
@@ -20,10 +20,12 @@ Request is a core Fastify object containing the following fields:
20
20
  - `ips` - an array of the IP addresses, ordered from closest to furthest, in the
21
21
  `X-Forwarded-For` header of the incoming request (only when the
22
22
  [`trustProxy`](./Server.md#factory-trust-proxy) option is enabled)
23
- - `hostname` - the host of the incoming request (derived from `X-Forwarded-Host`
23
+ - `host` - the host of the incoming request (derived from `X-Forwarded-Host`
24
24
  header when the [`trustProxy`](./Server.md#factory-trust-proxy) option is
25
25
  enabled). For HTTP/2 compatibility it returns `:authority` if no host header
26
26
  exists.
27
+ - `hostname` - the host of the incoming request without the port
28
+ - `port` - the port that the server is listening on
27
29
  - `protocol` - the protocol of the incoming request (`https` or `http`)
28
30
  - `method` - the method of the incoming request
29
31
  - `url` - the URL of the incoming request
@@ -104,7 +106,9 @@ fastify.post('/:params', options, function (request, reply) {
104
106
  console.log(request.id)
105
107
  console.log(request.ip)
106
108
  console.log(request.ips)
109
+ console.log(request.host)
107
110
  console.log(request.hostname)
111
+ console.log(request.port)
108
112
  console.log(request.protocol)
109
113
  console.log(request.url)
110
114
  console.log(request.routeOptions.method)
@@ -190,6 +190,24 @@ The above route declaration is more *Hapi*-like, but if you prefer an
190
190
 
191
191
  `fastify.patch(path, [options], handler)`
192
192
 
193
+ `fastify.propfind(path, [options], handler)`
194
+
195
+ `fastify.proppatch(path, [options], handler)`
196
+
197
+ `fastify.mkcol(path, [options], handler)`
198
+
199
+ `fastify.copy(path, [options], handler)`
200
+
201
+ `fastify.move(path, [options], handler)`
202
+
203
+ `fastify.lock(path, [options], handler)`
204
+
205
+ `fastify.unlock(path, [options], handler)`
206
+
207
+ `fastify.trace(path, [options], handler)`
208
+
209
+ `fastify.search(path, [options], handler)`
210
+
193
211
  Example:
194
212
  ```js
195
213
  const opts = {
@@ -578,7 +596,7 @@ const fastify = Fastify({
578
596
  method: req.method,
579
597
  url: req.url,
580
598
  headers: req.headers,
581
- hostname: req.hostname,
599
+ host: req.host,
582
600
  remoteAddress: req.ip,
583
601
  remotePort: req.socket.remotePort
584
602
  }
@@ -809,25 +827,3 @@ const secret = {
809
827
  > }
810
828
  > })
811
829
  > ```
812
-
813
-
814
- ### ⚠ HTTP version check
815
-
816
- Fastify will check the HTTP version of every request, based on configuration
817
- options ([http2](./Server.md#http2), [https](./Server.md#https), and
818
- [serverFactory](./Server.md#serverfactory)), to determine if it matches one or
819
- all of the > following versions: `2.0`, `1.1`, and `1.0`. If Fastify receives a
820
- different HTTP version in the request it will return a `505 HTTP Version Not
821
- Supported` error.
822
-
823
- | | 2.0 | 1.1 | 1.0 | skip |
824
- |:------------------------:|:---:|:---:|:---:|:----:|
825
- | http2 | ✓ | | | |
826
- | http2 + https | ✓ | | | |
827
- | http2 + https.allowHTTP1 | ✓ | ✓ | ✓ | |
828
- | https | | ✓ | ✓ | |
829
- | http | | ✓ | ✓ | |
830
- | serverFactory | | | | ✓ |
831
-
832
- Note: The internal HTTP version check will be removed in the future when Node
833
- implements [this feature](https://github.com/nodejs/node/issues/43115).
@@ -53,8 +53,6 @@ describes the properties available in that options object.
53
53
  - [listen](#listen)
54
54
  - [`listenTextResolver`](#listentextresolver)
55
55
  - [addresses](#addresses)
56
- - [getDefaultRoute](#getdefaultroute)
57
- - [setDefaultRoute](#setdefaultroute)
58
56
  - [routing](#routing)
59
57
  - [route](#route)
60
58
  - [hasRoute](#hasroute)
@@ -527,7 +525,15 @@ fastify.get('/user/:id(^([0-9]+){4}$)', (request, reply) => {
527
525
 
528
526
  The header name used to set the request-id. See [the
529
527
  request-id](./Logging.md#logging-request-id) section.
530
- Setting `requestIdHeader` to `false` will always use [genReqId](#genreqid).
528
+ Setting `requestIdHeader` to `true` will set the `requestIdHeader` to
529
+ `"request-id"`.
530
+ Setting `requestIdHeader` to a non-empty string will use
531
+ the specified string as the `requestIdHeader`.
532
+ By default `requestIdHeader` is set to `false` and will immediately use [genReqId](#genreqid).
533
+ Setting `requestIdHeader` to an empty String (`""`) will set the
534
+ requestIdHeader to `false`.
535
+
536
+ + Default: `false`
531
537
 
532
538
  ```js
533
539
  const fastify = require('fastify')({
@@ -596,14 +602,14 @@ const fastify = Fastify({ trustProxy: true })
596
602
  For more examples, refer to the
597
603
  [`proxy-addr`](https://www.npmjs.com/package/proxy-addr) package.
598
604
 
599
- You may access the `ip`, `ips`, `hostname` and `protocol` values on the
605
+ You may access the `ip`, `ips`, `host` and `protocol` values on the
600
606
  [`request`](./Request.md) object.
601
607
 
602
608
  ```js
603
609
  fastify.get('/', (request, reply) => {
604
610
  console.log(request.ip)
605
611
  console.log(request.ips)
606
- console.log(request.hostname)
612
+ console.log(request.host)
607
613
  console.log(request.protocol)
608
614
  })
609
615
  ```
@@ -871,14 +877,14 @@ function rewriteUrl (req) {
871
877
  ### `useSemicolonDelimiter`
872
878
  <a id="use-semicolon-delimiter"></a>
873
879
 
874
- + Default `true`
880
+ + Default `false`
875
881
 
876
882
  Fastify uses [find-my-way](https://github.com/delvedor/find-my-way) which supports,
877
883
  separating the path and query string with a `;` character (code 59), e.g. `/dev;foo=bar`.
878
884
  This decision originated from [delvedor/find-my-way#76]
879
885
  (https://github.com/delvedor/find-my-way/issues/76). Thus, this option will support
880
- backwards compatibility for the need to split on `;`. To disable support for splitting
881
- on `;` set `useSemicolonDelimiter` to `false`.
886
+ backwards compatiblilty for the need to split on `;`. To enable support for splitting
887
+ on `;` set `useSemicolonDelimiter` to `true`.
882
888
 
883
889
  ```js
884
890
  const fastify = require('fastify')({
@@ -1101,51 +1107,6 @@ const addresses = fastify.addresses()
1101
1107
 
1102
1108
  Note that the array contains the `fastify.server.address()` too.
1103
1109
 
1104
- #### getDefaultRoute
1105
- <a id="getDefaultRoute"></a>
1106
-
1107
- > **Warning**
1108
- > This method is deprecated and will be removed in the next Fastify
1109
- > major version.
1110
-
1111
- The `defaultRoute` handler handles requests that do not match any URL specified
1112
- by your Fastify application. This defaults to the 404 handler, but can be
1113
- overridden with [setDefaultRoute](#setdefaultroute). Method to get the
1114
- `defaultRoute` for the server:
1115
-
1116
- ```js
1117
- const defaultRoute = fastify.getDefaultRoute()
1118
- ```
1119
-
1120
- #### setDefaultRoute
1121
- <a id="setDefaultRoute"></a>
1122
-
1123
- > **Warning**
1124
- > This method is deprecated and will be removed in the next Fastify
1125
- > major version. Please, consider using `setNotFoundHandler` or a wildcard
1126
- > matching route.
1127
-
1128
- The default 404 handler, or one set using `setNotFoundHandler`, will
1129
- never trigger if the default route is overridden. This sets the handler for the
1130
- Fastify application, not just the current instance context. Use
1131
- [setNotFoundHandler](#setnotfoundhandler) if you want to customize 404 handling
1132
- instead.
1133
-
1134
- This method sets the `defaultRoute` for the server. Note that, its purpose is
1135
- to interact with the underlying raw requests. Unlike other Fastify handlers, the
1136
- arguments received are of type [RawRequest](./TypeScript.md#rawrequest) and
1137
- [RawReply](./TypeScript.md#rawreply) respectively.
1138
-
1139
- ```js
1140
- const defaultRoute = function (req, res) {
1141
- // req = RawRequest
1142
- // res = RawReply
1143
- res.end('hello world')
1144
- }
1145
-
1146
- fastify.setDefaultRoute(defaultRoute)
1147
- ```
1148
-
1149
1110
  #### routing
1150
1111
  <a id="routing"></a>
1151
1112
 
@@ -14,10 +14,8 @@
14
14
  - [FSTDEP008](#FSTDEP008)
15
15
  - [FSTDEP009](#FSTDEP009)
16
16
  - [FSTDEP010](#FSTDEP010)
17
- - [FSTDEP011](#FSTDEP011)
18
17
  - [FSTDEP012](#FSTDEP012)
19
18
  - [FSTDEP013](#FSTDEP013)
20
- - [FSTDEP014](#FSTDEP014)
21
19
  - [FSTDEP015](#FSTDEP015)
22
20
  - [FSTDEP016](#FSTDEP016)
23
21
  - [FSTDEP017](#FSTDEP017)
@@ -80,10 +78,8 @@ Deprecation codes are further supported by the Node.js CLI options:
80
78
  | <a id="FSTDEP008">FSTDEP008</a> | You are using route constraints via the route `{version: "..."}` option. | Use `{constraints: {version: "..."}}` option. | [#2682](https://github.com/fastify/fastify/pull/2682) |
81
79
  | <a id="FSTDEP009">FSTDEP009</a> | You are using a custom route versioning strategy via the server `{versioning: "..."}` option. | Use `{constraints: {version: "..."}}` option. | [#2682](https://github.com/fastify/fastify/pull/2682) |
82
80
  | <a id="FSTDEP010">FSTDEP010</a> | Modifying the `reply.sent` property is deprecated. | Use the `reply.hijack()` method. | [#3140](https://github.com/fastify/fastify/pull/3140) |
83
- | <a id="FSTDEP011">FSTDEP011</a> | Variadic listen method is deprecated. | Use `.listen(optionsObject)`. | [#3712](https://github.com/fastify/fastify/pull/3712) |
84
81
  | <a id="FSTDEP012">FSTDEP012</a> | You are trying to access the deprecated `request.context` property. | Use `request.routeOptions.config` or `request.routeOptions.schema`. | [#4216](https://github.com/fastify/fastify/pull/4216) [#5084](https://github.com/fastify/fastify/pull/5084) |
85
82
  | <a id="FSTDEP013">FSTDEP013</a> | Direct return of "trailers" function is deprecated. | Use "callback" or "async-await" for return value. | [#4380](https://github.com/fastify/fastify/pull/4380) |
86
- | <a id="FSTDEP014">FSTDEP014</a> | You are trying to set/access the default route. This property is deprecated. | Use `setNotFoundHandler` if you want to custom a 404 handler or the wildcard (`*`) to match all routes. | [#4480](https://github.com/fastify/fastify/pull/4480) |
87
83
  | <a id="FSTDEP015">FSTDEP015</a> | You are accessing the deprecated `request.routeSchema` property. | Use `request.routeOptions.schema`. | [#4470](https://github.com/fastify/fastify/pull/4470) |
88
84
  | <a id="FSTDEP016">FSTDEP016</a> | You are accessing the deprecated `request.routeConfig` property. | Use `request.routeOptions.config`. | [#4470](https://github.com/fastify/fastify/pull/4470) |
89
85
  | <a id="FSTDEP017">FSTDEP017</a> | You are accessing the deprecated `request.routerPath` property. | Use `request.routeOptions.url`. | [#4470](https://github.com/fastify/fastify/pull/4470) |
package/fastify.d.ts CHANGED
@@ -102,7 +102,8 @@ declare namespace fastify {
102
102
  exposeHeadRoutes?: boolean,
103
103
  onProtoPoisoning?: ProtoAction,
104
104
  onConstructorPoisoning?: ConstructorAction,
105
- logger?: boolean | FastifyLoggerOptions<RawServer> & PinoLoggerOptions | Logger,
105
+ logger?: boolean | FastifyLoggerOptions<RawServer> & PinoLoggerOptions,
106
+ loggerInstance?: Logger
106
107
  serializerOpts?: FJSOptions | Record<string, unknown>,
107
108
  serverFactory?: FastifyServerFactory<RawServer>,
108
109
  caseSensitive?: boolean,
package/fastify.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const VERSION = '4.27.0'
3
+ const VERSION = '5.0.0-aplha.1'
4
4
 
5
5
  const Avvio = require('avvio')
6
6
  const http = require('node:http')
@@ -32,7 +32,7 @@ const {
32
32
  kGenReqId
33
33
  } = require('./lib/symbols.js')
34
34
 
35
- const { createServer, compileValidateHTTPVersion } = require('./lib/server')
35
+ const { createServer } = require('./lib/server')
36
36
  const Reply = require('./lib/reply')
37
37
  const Request = require('./lib/request')
38
38
  const Context = require('./lib/context.js')
@@ -111,7 +111,7 @@ function fastify (options) {
111
111
 
112
112
  validateBodyLimitOption(options.bodyLimit)
113
113
 
114
- const requestIdHeader = (options.requestIdHeader === false) ? false : (options.requestIdHeader || defaultInitOptions.requestIdHeader).toLowerCase()
114
+ const requestIdHeader = typeof options.requestIdHeader === 'string' && options.requestIdHeader.length !== 0 ? options.requestIdHeader.toLowerCase() : (options.requestIdHeader === true && 'request-id')
115
115
  const genReqId = reqIdGenFactory(requestIdHeader, options.genReqId)
116
116
  const requestIdLogLabel = options.requestIdLogLabel || 'reqId'
117
117
  const bodyLimit = options.bodyLimit || defaultInitOptions.bodyLimit
@@ -252,8 +252,6 @@ function fastify (options) {
252
252
  [kGenReqId]: genReqId,
253
253
  // routing method
254
254
  routing: httpHandler,
255
- getDefaultRoute: router.getDefaultRoute.bind(router),
256
- setDefaultRoute: router.setDefaultRoute.bind(router),
257
255
  // routes shorthand methods
258
256
  delete: function _delete (url, options, handler) {
259
257
  return router.prepareRoute.call(this, { method: 'DELETE', url, options, handler })
@@ -276,6 +274,39 @@ function fastify (options) {
276
274
  options: function _options (url, options, handler) {
277
275
  return router.prepareRoute.call(this, { method: 'OPTIONS', url, options, handler })
278
276
  },
277
+ propfind: function _propfind (url, options, handler) {
278
+ return router.prepareRoute.call(this, { method: 'PROPFIND', url, options, handler })
279
+ },
280
+ proppatch: function _proppatch (url, options, handler) {
281
+ return router.prepareRoute.call(this, { method: 'PROPPATCH', url, options, handler })
282
+ },
283
+ mkcalendar: function _mkcalendar (url, options, handler) {
284
+ return router.prepareRoute.call(this, { method: 'MKCALENDAR', url, options, handler })
285
+ },
286
+ mkcol: function _mkcol (url, options, handler) {
287
+ return router.prepareRoute.call(this, { method: 'MKCOL', url, options, handler })
288
+ },
289
+ copy: function _copy (url, options, handler) {
290
+ return router.prepareRoute.call(this, { method: 'COPY', url, options, handler })
291
+ },
292
+ move: function _move (url, options, handler) {
293
+ return router.prepareRoute.call(this, { method: 'MOVE', url, options, handler })
294
+ },
295
+ lock: function _lock (url, options, handler) {
296
+ return router.prepareRoute.call(this, { method: 'LOCK', url, options, handler })
297
+ },
298
+ unlock: function _unlock (url, options, handler) {
299
+ return router.prepareRoute.call(this, { method: 'UNLOCK', url, options, handler })
300
+ },
301
+ trace: function _trace (url, options, handler) {
302
+ return router.prepareRoute.call(this, { method: 'TRACE', url, options, handler })
303
+ },
304
+ report: function _mkcalendar (url, options, handler) {
305
+ return router.prepareRoute.call(this, { method: 'REPORT', url, options, handler })
306
+ },
307
+ search: function _search (url, options, handler) {
308
+ return router.prepareRoute.call(this, { method: 'SEARCH', url, options, handler })
309
+ },
279
310
  all: function _all (url, options, handler) {
280
311
  return router.prepareRoute.call(this, { method: supportedMethods, url, options, handler })
281
312
  },
@@ -503,7 +534,6 @@ function fastify (options) {
503
534
  hasLogger,
504
535
  setupResponseListeners,
505
536
  throwIfAlreadyStarted,
506
- validateHTTPVersion: compileValidateHTTPVersion(options),
507
537
  keepAliveConnections
508
538
  })
509
539