fastify 4.12.0 → 4.13.0

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.
@@ -0,0 +1,170 @@
1
+ <h1 align="center">Fastify</h1>
2
+
3
+ # Detecting When Clients Abort
4
+
5
+ ## Introduction
6
+
7
+ Fastify provides request events to trigger at certain points in a request's
8
+ lifecycle. However, there isn't a built-in mechanism to
9
+ detect unintentional client disconnection scenarios such as when the client's
10
+ internet connection is interrupted. This guide covers methods to detect if
11
+ and when a client intentionally aborts a request.
12
+
13
+ Keep in mind, Fastify's `clientErrorHandler` is not designed to detect when a
14
+ client aborts a request. This works in the same way as the standard Node HTTP
15
+ module, which triggers the `clientError` event when there is a bad request or
16
+ exceedingly large header data. When a client aborts a request, there is no
17
+ error on the socket and the `clientErrorHandler` will not be triggered.
18
+
19
+ ## Solution
20
+
21
+ ### Overview
22
+
23
+ The proposed solution is a possible way of detecting when a client
24
+ intentionally aborts a request, such as when a browser is closed or the HTTP
25
+ request is aborted from your client application. If there is an error in your
26
+ application code that results in the server crashing, you may require
27
+ additional logic to avoid a false abort detection.
28
+
29
+ The goal here is to detect when a client intentionally aborts a connection
30
+ so your application logic can proceed accordingly. This can be useful for
31
+ logging purposes or halting business logic.
32
+
33
+ ### Hands-on
34
+
35
+ Say we have the following base server set up:
36
+
37
+ ```js
38
+ import Fastify from 'fastify';
39
+
40
+ const sleep = async (time) => {
41
+ return await new Promise(resolve => setTimeout(resolve, time || 1000));
42
+ }
43
+
44
+ const app = Fastify({
45
+ logger: {
46
+ transport: {
47
+ target: 'pino-pretty',
48
+ options: {
49
+ translateTime: 'HH:MM:ss Z',
50
+ ignore: 'pid,hostname',
51
+ },
52
+ },
53
+ },
54
+ })
55
+
56
+ app.addHook('onRequest', async (request, reply) => {
57
+ request.raw.on('close', () => {
58
+ if (request.raw.aborted) {
59
+ app.log.info('request closed')
60
+ }
61
+ })
62
+ })
63
+
64
+ app.get('/', async (request, reply) => {
65
+ await sleep(3000)
66
+ reply.code(200).send({ ok: true })
67
+ })
68
+
69
+ const start = async () => {
70
+ try {
71
+ await app.listen({ port: 3000 })
72
+ } catch (err) {
73
+ app.log.error(err)
74
+ process.exit(1)
75
+ }
76
+ }
77
+
78
+ start()
79
+ ```
80
+
81
+ Our code is setting up a Fastify server which includes the following
82
+ functionality:
83
+
84
+ - Accepting requests at http://localhost:3000, with a 3 second delayed response
85
+ of `{ ok: true }`.
86
+ - An onRequest hook that triggers when every request is received.
87
+ - Logic that triggers in the hook when the request is closed.
88
+ - Logging that occurs when the closed request property `aborted` is true.
89
+
90
+ In the request close event, you should examine the diff between a successful
91
+ request and one aborted by the client to determine the best property for your
92
+ use case. You can find details about request properties in the
93
+ [NodeJS documentation](https://nodejs.org/api/http.html).
94
+
95
+ You can also perform this logic outside of a hook, directly in a specific route.
96
+
97
+ ```js
98
+ app.get('/', async (request, reply) => {
99
+ request.raw.on('close', () => {
100
+ if (request.raw.aborted) {
101
+ app.log.info('request closed')
102
+ }
103
+ })
104
+ await sleep(3000)
105
+ reply.code(200).send({ ok: true })
106
+ })
107
+ ```
108
+
109
+ At any point in your business logic, you can check if the request has been
110
+ aborted and perform alternative actions.
111
+
112
+ ```js
113
+ app.get('/', async (request, reply) => {
114
+ await sleep(3000)
115
+ if (request.raw.aborted) {
116
+ // do something here
117
+ }
118
+ await sleep(3000)
119
+ reply.code(200).send({ ok: true })
120
+ })
121
+ ```
122
+
123
+ A benefit to adding this in your application code is that you can log Fastify
124
+ details such as the reqId, which may be unavailable in lower-level code that
125
+ only has access to the raw request information.
126
+
127
+ ### Testing
128
+
129
+ To test this functionality you can use an app like Postman and cancel your
130
+ request within 3 seconds. Alternatively, you can use Node to send an HTTP
131
+ request with logic to abort the request before 3 seconds. Example:
132
+
133
+ ```js
134
+ const controller = new AbortController();
135
+ const signal = controller.signal;
136
+
137
+ (async () => {
138
+ try {
139
+ const response = await fetch('http://localhost:3000', { signal });
140
+ const body = await response.text();
141
+ console.log(body);
142
+ } catch (error) {
143
+ console.error(error);
144
+ }
145
+ })();
146
+
147
+ setTimeout(() => {
148
+ controller.abort()
149
+ }, 1000);
150
+ ```
151
+
152
+ With either approach, you should see the Fastify log appear at the moment the
153
+ request is aborted.
154
+
155
+ ## Conclusion
156
+
157
+ Specifics of the implementation will vary from one problem to another, but the
158
+ main goal of this guide was to show a very specific use case of an issue that
159
+ could be solved within Fastify's ecosystem.
160
+
161
+ You can listen to the request close event and determine if the request was
162
+ aborted or if it was successfully delivered. You can implement this solution
163
+ in an onRequest hook or directly in an individual route.
164
+
165
+ This approach will not trigger in the event of internet disruption, and such
166
+ detection would require additional business logic. If you have flawed backend
167
+ application logic that results in a server crash, then you could trigger a
168
+ false detection. The `clientErrorHandler`, either by default or with custom
169
+ logic, is not intended to handle this scenario and will not trigger when the
170
+ client aborts a request.
@@ -140,6 +140,8 @@ section.
140
140
 
141
141
  - [`@applicazza/fastify-nextjs`](https://github.com/applicazza/fastify-nextjs)
142
142
  Alternate Fastify and Next.js integration.
143
+ - [`@clerk/fastify`](https://github.com/clerkinc/javascript/tree/main/packages/fastify)
144
+ Add authentication and user management to your Fastify application with Clerk.
143
145
  - [`@coobaha/typed-fastify`](https://github.com/Coobaha/typed-fastify) Strongly
144
146
  typed routes with a runtime validation using JSON schema generated from types.
145
147
  - [`@dnlup/fastify-doc`](https://github.com/dnlup/fastify-doc) A plugin for
@@ -201,6 +203,8 @@ section.
201
203
  using Fastify without the need of consuming a port on Electron apps.
202
204
  - [`fast-water`](https://github.com/tswayne/fast-water) A Fastify plugin for
203
205
  waterline. Decorates Fastify with waterline models.
206
+ - [`fastify-204`](https://github.com/Shiva127/fastify-204) Fastify plugin that
207
+ return 204 status on empty response.
204
208
  - [`fastify-405`](https://github.com/Eomm/fastify-405) Fastify plugin that adds
205
209
  405 HTTP status to your routes
206
210
  - [`fastify-allow`](https://github.com/mattbishop/fastify-allow) Fastify plugin
@@ -266,6 +270,10 @@ section.
266
270
  - [`fastify-cloudevents`](https://github.com/smartiniOnGitHub/fastify-cloudevents)
267
271
  Fastify plugin to generate and forward Fastify events in the Cloudevents
268
272
  format.
273
+ - [`fastify-cloudinary`](https://github.com/Vanilla-IceCream/fastify-cloudinary)
274
+ The Cloudinary Fastify SDK allows you to quickly and easily integrate your
275
+ application with Cloudinary. Effortlessly optimize and transform your cloud's
276
+ assets.
269
277
  - [`fastify-cockroachdb`](https://github.com/alex-ppg/fastify-cockroachdb)
270
278
  Fastify plugin to connect to a CockroachDB PostgreSQL instance via the
271
279
  Sequelize ORM.
@@ -280,6 +288,9 @@ section.
280
288
  functions.
281
289
  - [`fastify-decorators`](https://github.com/L2jLiga/fastify-decorators) Fastify
282
290
  plugin that provides the set of TypeScript decorators.
291
+ - [`fastify-delay-request`](https://github.com/climba03003/fastify-delay-request)
292
+ Fastify plugin that allows requests to be delayed whilst a task the response is
293
+ dependent on is run, such as a resource intensive process.
283
294
  - [`fastify-disablecache`](https://github.com/Fdawgs/fastify-disablecache)
284
295
  Fastify plugin to disable client-side caching, inspired by
285
296
  [nocache](https://github.com/helmetjs/nocache).
@@ -369,6 +380,8 @@ section.
369
380
  - [`fastify-ip`](https://github.com/metcoder95/fastify-ip) A plugin
370
381
  for Fastify that allows you to infer a request ID by a
371
382
  given set of custom Request headers.
383
+ - [`fastify-json-to-xml`](https://github.com/Fdawgs/fastify-json-to-xml) Fastify
384
+ plugin to serialize JSON responses into XML.
372
385
  - [`fastify-jwt-authz`](https://github.com/Ethan-Arrowood/fastify-jwt-authz) JWT
373
386
  user scope verifier.
374
387
  - [`fastify-jwt-webapp`](https://github.com/charlesread/fastify-jwt-webapp) JWT
@@ -387,7 +400,7 @@ section.
387
400
  Fastify plugin to parse request language.
388
401
  - [`fastify-lcache`](https://github.com/denbon05/fastify-lcache)
389
402
  Lightweight cache plugin
390
- - [`fastify-list-routes`](https://github.com/chuongtrh/fastify-list-routes)
403
+ - [`fastify-list-routes`](https://github.com/chuongtrh/fastify-list-routes)
391
404
  A simple plugin for Fastify list all available routes.
392
405
  - [`fastify-loader`](https://github.com/TheNoim/fastify-loader) Load routes from
393
406
  a directory and inject the Fastify instance in each file.
@@ -537,9 +550,11 @@ section.
537
550
  - [`fastify-server-session`](https://github.com/jsumners/fastify-server-session)
538
551
  A session plugin with support for arbitrary backing caches via
539
552
  `fastify-caching`.
553
+ - [`fastify-shared-schema`](https://github.com/Adibla/fastify-shared-schema) Plugin
554
+ for sharing schemas between different routes.
540
555
  - [`fastify-slonik`](https://github.com/Unbuttun/fastify-slonik) Fastify Slonik
541
556
  plugin, with this you can use slonik in every part of your server.
542
- - [`fastify-slow-down`](https://github.com/nearform/fastify-slow-down) A plugin
557
+ - [`fastify-slow-down`](https://github.com/nearform/fastify-slow-down) A plugin
543
558
  to delay the response from the server.
544
559
  - [`fastify-socket.io`](https://github.com/alemagio/fastify-socket.io) a
545
560
  Socket.io plugin for Fastify.
@@ -590,6 +605,8 @@ section.
590
605
  should use.
591
606
  - [`fastify-wamp-router`](https://github.com/lependu/fastify-wamp-router) Web
592
607
  Application Messaging Protocol router for Fastify.
608
+ - [`fastify-web-response`](https://github.com/erfanium/fastify-web-response)
609
+ Enables returning web streams objects `Response` and `ReadableStream` in routes.
593
610
  - [`fastify-webpack-hmr`](https://github.com/lependu/fastify-webpack-hmr)
594
611
  Webpack hot module reloading plugin for Fastify.
595
612
  - [`fastify-webpack-hot`](https://github.com/gajus/fastify-webpack-hot) Webpack
@@ -626,7 +643,6 @@ section.
626
643
  and lightweight Sequelize plugin for Fastify.
627
644
  - [`typeorm-fastify-plugin`](https://github.com/jclemens24/fastify-typeorm) A simple
628
645
  and updated Typeorm plugin for use with Fastify.
629
-
630
646
  #### [Community Tools](#community-tools)
631
647
  - [`@fastify-userland/workflows`](https://github.com/fastify-userland/workflows)
632
648
  Reusable workflows for use in the Fastify plugin
@@ -15,6 +15,8 @@ This table of contents is in alphabetical order.
15
15
  met in your application. This guide focuses on solving the problem using
16
16
  [`Hooks`](../Reference/Hooks.md), [`Decorators`](../Reference/Decorators.md),
17
17
  and [`Plugins`](../Reference/Plugins.md).
18
+ + [Detecting When Clients Abort](./Detecting-When-Clients-Abort.md): A
19
+ practical guide on detecting if and when a client aborts a request.
18
20
  + [Ecosystem](./Ecosystem.md): Lists all core plugins and many known community
19
21
  plugins.
20
22
  + [Fluent Schema](./Fluent-Schema.md): Shows how writing JSON Schema can be
@@ -121,7 +121,7 @@ As a result, if you specify an `onRoute` hook in a plugin you should now either:
121
121
 
122
122
  Into this:
123
123
  ```js
124
- await fastify.register((instance, opts) => {
124
+ await fastify.register((instance, opts, done) => {
125
125
  instance.addHook('onRoute', (routeOptions) => {
126
126
  const { path, method } = routeOptions;
127
127
  console.log({ path, method });
@@ -133,7 +133,43 @@ fastify.listen({ port: 3000 }, function (err, address) {
133
133
 
134
134
  404 Not Found.
135
135
 
136
+ #### FST_ERR_OPTIONS_NOT_OBJ
137
+ <a id="FST_ERR_OPTIONS_NOT_OBJ"></a>
138
+
139
+ Fastify options must be an object.
140
+
141
+ #### FST_ERR_QSP_NOT_FN
142
+ <a id="FST_ERR_QSP_NOT_FN"></a>
143
+
144
+ QueryStringParser option should be a function.
145
+
146
+ #### FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN
147
+ <a id="FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN"></a>
148
+
149
+ SchemaController.bucket option should be a function.
150
+
151
+ #### FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN
152
+ <a id="FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN"></a>
153
+
154
+ SchemaErrorFormatter option should be a non async function.
155
+
156
+ #### FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ
157
+ <a id="FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ"></a>
158
+
159
+ ajv.customOptions option should be an object.
160
+
161
+ #### FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR
162
+ <a id="FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR"></a>
163
+
164
+ ajv.plugins option should be an array.
165
+
166
+ #### FST_ERR_VERSION_CONSTRAINT_NOT_STR
167
+ <a id="FST_ERR_VERSION_CONSTRAINT_NOT_STR"></a>
168
+
169
+ Version constraint should be a string.
170
+
136
171
  <a name="FST_ERR_CTP_ALREADY_PRESENT"></a>
172
+
137
173
  #### FST_ERR_CTP_ALREADY_PRESENT
138
174
  <a id="FST_ERR_CTP_ALREADY_PRESENT"></a>
139
175
 
@@ -184,6 +220,16 @@ Request body size did not match `Content-Length`.
184
220
 
185
221
  Body cannot be empty when content-type is set to `application/json`.
186
222
 
223
+ #### FST_ERR_CTP_INSTANCE_ALREADY_STARTED
224
+ <a id="FST_ERR_CTP_INSTANCE_ALREADY_STARTED"></a>
225
+
226
+ Fastify is already started.
227
+
228
+ #### FST_ERR_INSTANCE_ALREADY_LISTENING
229
+ <a id="FST_ERR_INSTANCE_ALREADY_LISTENING"></a>
230
+
231
+ Fastify instance is already listening.
232
+
187
233
  #### FST_ERR_DEC_ALREADY_PRESENT
188
234
  <a id="FST_ERR_DEC_ALREADY_PRESENT"></a>
189
235
 
@@ -214,10 +260,15 @@ The hook name must be a string.
214
260
 
215
261
  The hook callback must be a function.
216
262
 
263
+ #### FST_ERR_HOOK_NOT_SUPPORTED
264
+ <a id="FST_ERR_HOOK_NOT_SUPPORTED"></a>
265
+
266
+ The hook is not supported.
267
+
217
268
  #### FST_ERR_MISSING_MIDDLEWARE
218
269
  <a id="FST_ERR_MISSING_MIDDLEWARE"></a>
219
270
 
220
- You must register a plugin for handling middlewares,
271
+ You must register a plugin for handling middlewares,
221
272
  visit [`Middleware`](./Middleware.md) for more info.
222
273
 
223
274
  <a name="FST_ERR_HOOK_TIMEOUT"></a>
@@ -278,7 +329,7 @@ Missing serialization function.
278
329
  #### FST_ERR_REQ_INVALID_VALIDATION_INVOCATION
279
330
  <a id="FST_ERR_REQ_INVALID_VALIDATION_INVOCATION"></a>
280
331
 
281
- Invalid validation invocation. Missing validation function for
332
+ Invalid validation invocation. Missing validation function for
282
333
  HTTP part nor schema provided.
283
334
 
284
335
  #### FST_ERR_SCH_MISSING_ID
@@ -306,6 +357,11 @@ The JSON schema provided for validation to a route is not valid.
306
357
 
307
358
  The JSON schema provided for serialization of a route response is not valid.
308
359
 
360
+ #### FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX
361
+ <a id="FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX"></a>
362
+
363
+ Response schemas should be nested under a valid status code (2XX).
364
+
309
365
  #### FST_ERR_HTTP2_INVALID_VERSION
310
366
  <a id="FST_ERR_HTTP2_INVALID_VERSION"></a>
311
367
 
@@ -319,7 +375,7 @@ Invalid initialization options.
319
375
  #### FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE
320
376
  <a id="FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE"></a>
321
377
 
322
- Cannot set forceCloseConnections to `idle` as your HTTP server
378
+ Cannot set forceCloseConnections to `idle` as your HTTP server
323
379
  does not support `closeIdleConnections` method.
324
380
 
325
381
  <a name="FST_ERR_DUPLICATED_ROUTE"></a>
@@ -347,6 +403,46 @@ The `defaultRoute` type should be a function.
347
403
 
348
404
  URL must be a string.
349
405
 
406
+ #### FST_ERR_ROUTE_OPTIONS_NOT_OBJ
407
+ <a id="FST_ERR_ROUTE_OPTIONS_NOT_OBJ"></a>
408
+
409
+ Options for the route must be an object.
410
+
411
+ #### FST_ERR_ROUTE_DUPLICATED_HANDLER
412
+ <a id="FST_ERR_ROUTE_DUPLICATED_HANDLER"></a>
413
+
414
+ Duplicate handler for the route is not allowed.
415
+
416
+ #### FST_ERR_ROUTE_HANDLER_NOT_FN
417
+ <a id="FST_ERR_ROUTE_HANDLER_NOT_FN"></a>
418
+
419
+ Handler for the route must be a function.
420
+
421
+ #### FST_ERR_ROUTE_MISSING_HANDLER
422
+ <a id="FST_ERR_ROUTE_MISSING_HANDLER"></a>
423
+
424
+ Missing handler function for the route.
425
+
426
+ #### FST_ERR_ROUTE_METHOD_NOT_SUPPORTED
427
+ <a id="FST_ERR_ROUTE_METHOD_NOT_SUPPORTED"></a>
428
+
429
+ Method is not supported for the route.
430
+
431
+ #### FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED
432
+ <a id="FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED"></a>
433
+
434
+ Body validation schema route is not supported.
435
+
436
+ #### FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT
437
+ <a id="FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT"></a>
438
+
439
+ BodyLimit option must be an integer.
440
+
441
+ #### FST_ERR_ROUTE_REWRITE_NOT_STR
442
+ <a id="FST_ERR_ROUTE_REWRITE_NOT_STR"></a>
443
+
444
+ Rewrite url needs to be of type "string".
445
+
350
446
  #### FST_ERR_REOPENED_CLOSE_SERVER
351
447
  <a id="FST_ERR_REOPENED_CLOSE_SERVER"></a>
352
448
 
@@ -363,26 +459,37 @@ Fastify is already listening.
363
459
  Installed Fastify plugin mismatched expected version.
364
460
 
365
461
  <a name="FST_ERR_PLUGIN_CALLBACK_NOT_FN"></a>
462
+
366
463
  #### FST_ERR_PLUGIN_CALLBACK_NOT_FN
367
464
 
368
465
  Callback for a hook is not a function (mapped directly from `avvio`)
369
466
 
370
467
  <a name="FST_ERR_PLUGIN_NOT_VALID"></a>
468
+
371
469
  #### FST_ERR_PLUGIN_NOT_VALID
372
470
 
373
471
  Plugin must be a function or a promise.
374
472
 
375
473
  <a name="FST_ERR_ROOT_PLG_BOOTED"></a>
474
+
376
475
  #### FST_ERR_ROOT_PLG_BOOTED
377
476
 
378
477
  Root plugin has already booted (mapped directly from `avvio`)
379
478
 
380
479
  <a name="FST_ERR_PARENT_PLUGIN_BOOTED"></a>
480
+
381
481
  #### FST_ERR_PARENT_PLUGIN_BOOTED
382
482
 
383
483
  Impossible to load plugin because the parent (mapped directly from `avvio`)
384
484
 
385
485
  <a name="FST_ERR_PLUGIN_TIMEOUT"></a>
486
+
386
487
  #### FST_ERR_PLUGIN_TIMEOUT
387
488
 
388
489
  Plugin did not start in time. Default timeout (in millis): `10000`
490
+
491
+ <a name="FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE"></a>
492
+
493
+ #### FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE
494
+
495
+ The decorator is not present in the instance.
@@ -9,6 +9,7 @@ options object which is used to customize the resulting instance. This document
9
9
  describes the properties available in that options object.
10
10
 
11
11
  - [Factory](#factory)
12
+ - [`http`](#http)
12
13
  - [`http2`](#http2)
13
14
  - [`https`](#https)
14
15
  - [`connectionTimeout`](#connectiontimeout)
@@ -91,6 +92,18 @@ describes the properties available in that options object.
91
92
  - [errorHandler](#errorhandler)
92
93
  - [initialConfig](#initialconfig)
93
94
 
95
+ ### `http`
96
+ <a id="factory-http"></a>
97
+
98
+ An object used to configure the server's listening socket. The options
99
+ are the same as the Node.js core [`createServer`
100
+ method](https://nodejs.org/dist/latest-v14.x/docs/api/http.html#http_http_createserver_options_requestlistener).
101
+
102
+ This option is ignored if options [`http2`](#factory-http2) or
103
+ [`https`](#factory-https) are set.
104
+
105
+ + Default: `null`
106
+
94
107
  ### `http2`
95
108
  <a id="factory-http2"></a>
96
109
 
@@ -494,7 +507,7 @@ request-id](./Logging.md#logging-request-id) section.
494
507
  Setting `requestIdHeader` to `false` will always use [genReqId](#genreqid)
495
508
 
496
509
  + Default: `'request-id'`
497
-
510
+
498
511
  ```js
499
512
  const fastify = require('fastify')({
500
513
  requestIdHeader: 'x-custom-id', // -> use 'X-Custom-Id' header if available
@@ -1440,9 +1453,9 @@ plugins are registered. If you would like to augment the behavior of the default
1440
1453
  arguments `fastify.setNotFoundHandler()` within the context of these registered
1441
1454
  plugins.
1442
1455
 
1443
- > Note: Some config properties from the request object will be
1456
+ > Note: Some config properties from the request object will be
1444
1457
  > undefined inside the custom not found handler. E.g:
1445
- > `request.routerPath`, `routerMethod` and `context.config`.
1458
+ > `request.routerPath`, `routerMethod` and `context.config`.
1446
1459
  > This method design goal is to allow calling the common not found route.
1447
1460
  > To return a per-route customized 404 response, you can do it in
1448
1461
  > the response itself.
@@ -394,9 +394,11 @@ configuration](https://github.com/fastify/ajv-compiler#ajv-configuration) is:
394
394
 
395
395
  ```js
396
396
  {
397
- coerceTypes: true, // change data type of data to match type keyword
397
+ coerceTypes: 'array', // change data type of data to match type keyword
398
398
  useDefaults: true, // replace missing properties and items with the values from corresponding default keyword
399
399
  removeAdditional: true, // remove additional properties
400
+ uriResolver: require('fast-uri'),
401
+ addUsedSchema: false,
400
402
  // Explicitly set allErrors to `false`.
401
403
  // When set to `true`, a DoS attack is possible.
402
404
  allErrors: false
package/fastify.d.ts CHANGED
@@ -61,6 +61,13 @@ declare namespace fastify {
61
61
  https: https.ServerOptions | null
62
62
  }
63
63
 
64
+ export type FastifyHttpOptions<
65
+ Server extends http.Server,
66
+ Logger extends FastifyBaseLogger = FastifyBaseLogger
67
+ > = FastifyServerOptions<Server, Logger> & {
68
+ http?: http.ServerOptions | null
69
+ }
70
+
64
71
  type FindMyWayVersion<RawServer extends RawServerBase> = RawServer extends http.Server ? HTTPVersion.V1 : HTTPVersion.V2
65
72
 
66
73
  export interface ConnectionError extends Error {
@@ -224,7 +231,7 @@ declare function fastify<
224
231
  Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,
225
232
  Logger extends FastifyBaseLogger = FastifyBaseLogger,
226
233
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
227
- >(opts?: fastify.FastifyServerOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger, TypeProvider> & PromiseLike<FastifyInstance<Server, Request, Reply, Logger, TypeProvider>>
234
+ >(opts?: fastify.FastifyHttpOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger, TypeProvider> & PromiseLike<FastifyInstance<Server, Request, Reply, Logger, TypeProvider>>
228
235
 
229
236
  // CJS export
230
237
  // const fastify = require('fastify')