fastify 5.2.0 → 5.2.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.
package/README.md CHANGED
@@ -284,34 +284,31 @@ listed in alphabetical order.
284
284
  <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
285
285
  * [__Tomas Della Vedova__](https://github.com/delvedor),
286
286
  <https://twitter.com/delvedor>, <https://www.npmjs.com/~delvedor>
287
+ * [__KaKa Ng__](https://github.com/climba03003),
288
+ <https://www.npmjs.com/~climba03003>
287
289
  * [__Manuel Spigolon__](https://github.com/eomm),
288
290
  <https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm>
289
291
  * [__James Sumners__](https://github.com/jsumners),
290
292
  <https://twitter.com/jsumners79>, <https://www.npmjs.com/~jsumners>
291
293
 
292
294
  ### Fastify Core team
293
- * [__Tommaso Allevi__](https://github.com/allevo),
294
- <https://twitter.com/allevitommaso>, <https://www.npmjs.com/~allevo>
295
+ * [__Aras Abbasi__](https://github.com/uzlopak),
296
+ <https://www.npmjs.com/~uzlopak>
295
297
  * [__Harry Brundage__](https://github.com/airhorns/),
296
298
  <https://twitter.com/harrybrundage>, <https://www.npmjs.com/~airhorns>
297
- * [__David Mark Clements__](https://github.com/davidmarkclements),
298
- <https://twitter.com/davidmarkclem>,
299
- <https://www.npmjs.com/~davidmarkclements>
300
299
  * [__Matteo Collina__](https://github.com/mcollina),
301
300
  <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
301
+ * [__Gürgün Dayıoğlu__](https://github.com/gurgunday),
302
+ <https://www.npmjs.com/~gurgunday>
302
303
  * [__Tomas Della Vedova__](https://github.com/delvedor),
303
304
  <https://twitter.com/delvedor>, <https://www.npmjs.com/~delvedor>
304
- * [__Dustin Deus__](https://github.com/StarpTech),
305
- <https://twitter.com/dustindeus>, <https://www.npmjs.com/~starptech>
306
- * [__Ayoub El Khattabi__](https://github.com/AyoubElk),
307
- <https://twitter.com/ayoubelkh>, <https://www.npmjs.com/~ayoubelk>
308
- * [__Denis Fäcke__](https://github.com/SerayaEryn),
309
- <https://twitter.com/serayaeryn>, <https://www.npmjs.com/~serayaeryn>
310
305
  * [__Carlos Fuentes__](https://github.com/metcoder95),
311
306
  <https://twitter.com/metcoder95>, <https://www.npmjs.com/~metcoder95>
312
307
  * [__Vincent Le Goff__](https://github.com/zekth)
313
308
  * [__Luciano Mammino__](https://github.com/lmammino),
314
309
  <https://twitter.com/loige>, <https://www.npmjs.com/~lmammino>
310
+ * [__KaKa Ng__](https://github.com/climba03003),
311
+ <https://www.npmjs.com/~climba03003>
315
312
  * [__Luis Orbaiceta__](https://github.com/luisorbaiceta),
316
313
  <https://twitter.com/luisorbai>, <https://www.npmjs.com/~luisorbaiceta>
317
314
  * [__Maksim Sinik__](https://github.com/fox1t),
@@ -320,63 +317,65 @@ listed in alphabetical order.
320
317
  <https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm>
321
318
  * [__James Sumners__](https://github.com/jsumners),
322
319
  <https://twitter.com/jsumners79>, <https://www.npmjs.com/~jsumners>
323
- * [__Aras Abbasi__](https://github.com/uzlopak),
324
- <https://www.npmjs.com/~uzlopak>
325
- * [__Gürgün Dayıoğlu__](https://github.com/gurgunday),
326
- <https://www.npmjs.com/~gurgunday>
327
320
 
328
321
  ### Fastify Plugins team
329
- * [__Matteo Collina__](https://github.com/mcollina),
330
- <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
331
322
  * [__Harry Brundage__](https://github.com/airhorns/),
332
323
  <https://twitter.com/harrybrundage>, <https://www.npmjs.com/~airhorns>
324
+ * [__Simone Busoli__](https://github.com/simoneb),
325
+ <https://twitter.com/simonebu>, <https://www.npmjs.com/~simoneb>
326
+ * [__Dan Castillo__](https://github.com/dancastillo),
327
+ <https://www.npmjs.com/~dancastillo>
328
+ * [__Matteo Collina__](https://github.com/mcollina),
329
+ <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
330
+ * [__Gürgün Dayıoğlu__](https://github.com/gurgunday),
331
+ <https://www.npmjs.com/~gurgunday>
333
332
  * [__Tomas Della Vedova__](https://github.com/delvedor),
334
333
  <https://twitter.com/delvedor>, <https://www.npmjs.com/~delvedor>
335
- * [__Ayoub El Khattabi__](https://github.com/AyoubElk),
336
- <https://twitter.com/ayoubelkh>, <https://www.npmjs.com/~ayoubelk>
337
334
  * [__Carlos Fuentes__](https://github.com/metcoder95),
338
335
  <https://twitter.com/metcoder95>, <https://www.npmjs.com/~metcoder95>
339
336
  * [__Vincent Le Goff__](https://github.com/zekth)
340
- * [__Salman Mitha__](https://github.com/salmanm),
341
- <https://www.npmjs.com/~salmanm>
337
+ * [__Jean Michelet__](https://github.com/jean-michelet),
338
+ <https://www.npmjs.com/~jean-michelet>
339
+ * [__KaKa Ng__](https://github.com/climba03003),
340
+ <https://www.npmjs.com/~climba03003>
342
341
  * [__Maksim Sinik__](https://github.com/fox1t),
343
342
  <https://twitter.com/maksimsinik>, <https://www.npmjs.com/~fox1t>
344
343
  * [__Frazer Smith__](https://github.com/Fdawgs), <https://www.npmjs.com/~fdawgs>
345
344
  * [__Manuel Spigolon__](https://github.com/eomm),
346
345
  <https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm>
347
- * [__Simone Busoli__](https://github.com/simoneb),
348
- <https://twitter.com/simonebu>, <https://www.npmjs.com/~simoneb>
349
- * [__Gürgün Dayıoğlu__](https://github.com/gurgunday),
350
- <https://www.npmjs.com/~gurgunday>
351
- * [__Dan Castillo__](https://github.com/dancastillo),
352
- <https://www.npmjs.com/~dancastillo>
353
- * [__Jean Michelet__](https://github.com/jean-michelet),
354
- <https://www.npmjs.com/~jean-michelet>
355
346
 
356
- ### Great Contributors
347
+ ### Emeritus Contributors
357
348
  Great contributors on a specific area in the Fastify ecosystem will be invited
358
- to join this group by Lead Maintainers.
359
-
360
- * [__dalisoft__](https://github.com/dalisoft), <https://twitter.com/dalisoft>,
361
- <https://www.npmjs.com/~dalisoft>
362
- * [__Luciano Mammino__](https://github.com/lmammino),
363
- <https://twitter.com/loige>, <https://www.npmjs.com/~lmammino>
364
- * [__Evan Shortiss__](https://github.com/evanshortiss),
365
- <https://twitter.com/evanshortiss>, <https://www.npmjs.com/~evanshortiss>
349
+ to join this group by Lead Maintainers when they decide to step down from the
350
+ active contributors group.
366
351
 
367
- **Past Collaborators**
352
+ * [__Tommaso Allevi__](https://github.com/allevo),
353
+ <https://twitter.com/allevitommaso>, <https://www.npmjs.com/~allevo>
354
+ * [__Ethan Arrowood__](https://github.com/Ethan-Arrowood/),
355
+ <https://twitter.com/arrowoodtech>, <https://www.npmjs.com/~ethan_arrowood>
368
356
  * [__Çağatay Çalı__](https://github.com/cagataycali),
369
357
  <https://twitter.com/cagataycali>, <https://www.npmjs.com/~cagataycali>
358
+ * [__David Mark Clements__](https://github.com/davidmarkclements),
359
+ <https://twitter.com/davidmarkclem>,
360
+ <https://www.npmjs.com/~davidmarkclements>
361
+ * [__dalisoft__](https://github.com/dalisoft), <https://twitter.com/dalisoft>,
362
+ <https://www.npmjs.com/~dalisoft>
363
+ * [__Dustin Deus__](https://github.com/StarpTech),
364
+ <https://twitter.com/dustindeus>, <https://www.npmjs.com/~starptech>
365
+ * [__Denis Fäcke__](https://github.com/SerayaEryn),
366
+ <https://twitter.com/serayaeryn>, <https://www.npmjs.com/~serayaeryn>
367
+ * [__Rafael Gonzaga__](https://github.com/rafaelgss),
368
+ <https://twitter.com/_rafaelgss>, <https://www.npmjs.com/~rafaelgss>
370
369
  * [__Trivikram Kamat__](https://github.com/trivikr),
371
370
  <https://twitter.com/trivikram>, <https://www.npmjs.com/~trivikr>
371
+ * [__Ayoub El Khattabi__](https://github.com/AyoubElk),
372
+ <https://twitter.com/ayoubelkh>, <https://www.npmjs.com/~ayoubelk>
372
373
  * [__Cemre Mengu__](https://github.com/cemremengu),
373
374
  <https://twitter.com/cemremengu>, <https://www.npmjs.com/~cemremengu>
375
+ * [__Salman Mitha__](https://github.com/salmanm),
376
+ <https://www.npmjs.com/~salmanm>
374
377
  * [__Nathan Woltman__](https://github.com/nwoltman),
375
378
  <https://twitter.com/NathanWoltman>, <https://www.npmjs.com/~nwoltman>
376
- * [__Ethan Arrowood__](https://github.com/Ethan-Arrowood/),
377
- <https://twitter.com/arrowoodtech>, <https://www.npmjs.com/~ethan_arrowood>
378
- * [__Rafael Gonzaga__](https://github.com/rafaelgss),
379
- <https://twitter.com/_rafaelgss>, <https://www.npmjs.com/~rafaelgss>
380
379
 
381
380
  ## Hosted by
382
381
 
@@ -8,7 +8,7 @@ const path = require('node:path')
8
8
  const factory = AjvStandaloneCompiler({
9
9
  readMode: false,
10
10
  storeFunction (routeOpts, schemaValidationCode) {
11
- const moduleCode = `// This file is autogenerated by ${__filename.replace(__dirname, 'build')}, do not edit
11
+ const moduleCode = `// This file is autogenerated by build/build-validation.js, do not edit
12
12
  /* c8 ignore start */
13
13
  ${schemaValidationCode}
14
14
 
@@ -49,6 +49,7 @@
49
49
  - [FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED](#fst_err_log_logger_and_logger_instance_provided)
50
50
  - [FST_ERR_REP_INVALID_PAYLOAD_TYPE](#fst_err_rep_invalid_payload_type)
51
51
  - [FST_ERR_REP_RESPONSE_BODY_CONSUMED](#fst_err_rep_response_body_consumed)
52
+ - [FST_ERR_REP_READABLE_STREAM_LOCKED](#fst_err_rep_readable_stream_locked)
52
53
  - [FST_ERR_REP_ALREADY_SENT](#fst_err_rep_already_sent)
53
54
  - [FST_ERR_REP_SENT_VALUE](#fst_err_rep_sent_value)
54
55
  - [FST_ERR_SEND_INSIDE_ONERR](#fst_err_send_inside_onerr)
@@ -321,6 +322,7 @@ Below is a table with all the error codes that Fastify uses.
321
322
  | <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) |
322
323
  | <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) |
323
324
  | <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) |
325
+ | <a id="fst_err_rep_readable_stream_locked">FST_ERR_REP_READABLE_STREAM_LOCKED</a> | Using `ReadableStream` as reply payload, but locked with another reader. | Make sure you don't call the `Readable.getReader` before sending or release lock with `reader.releaseLock()` before sending. | [#5920](https://github.com/fastify/fastify/pull/5920) |
324
326
  | <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) |
325
327
  | <a id="fst_err_rep_sent_value">FST_ERR_REP_SENT_VALUE</a> | The only possible value for `reply.sent` is `true`. | - | [#1336](https://github.com/fastify/fastify/pull/1336) |
326
328
  | <a id="fst_err_send_inside_onerr">FST_ERR_SEND_INSIDE_ONERR</a> | You cannot use `send` inside the `onError` hook. | - | [#1348](https://github.com/fastify/fastify/pull/1348) |
@@ -23,13 +23,12 @@ Request is a core Fastify object containing the following fields:
23
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
- exists. The host header may return empty string when using
27
- `requireHostHeader = false`, not suppied when connected with `HTTP/1.0` or
28
- using schema validation that remove the extra headers.
29
- - `hostname` - the host of the `host` property, it may refers the incoming
30
- request hostname
31
- - `port` - the port of the `host` property, it may refers the port thats
32
- the server is listening on
26
+ exists. The host header may return an empty string if `requireHostHeader`
27
+ is false, not provided with HTTP/1.0, or removed by schema validation.
28
+ - `hostname` - the hostname derived from the `host` property of
29
+ the incoming request
30
+ - `port` - the port from the `host` property, which may refer to
31
+ the port the server is listening on
33
32
  - `protocol` - the protocol of the incoming request (`https` or `http`)
34
33
  - `method` - the method of the incoming request
35
34
  - `url` - the URL of the incoming request
@@ -88,8 +87,8 @@ request's headers with the `request.raw.headers` property.
88
87
  > Note: For performance reason on `not found` route, you may see that we will
89
88
  add an extra property `Symbol('fastify.RequestAcceptVersion')` on the headers.
90
89
 
91
- > Note: When using schema, it may mutate the `request.headers` and
92
- `request.raw.headers` object. So, you may found the headers becomes empty.
90
+ > Note: Using schema validation may mutate the `request.headers` and
91
+ `request.raw.headers` objects, causing the headers to become empty.
93
92
 
94
93
  ```js
95
94
  fastify.post('/:params', options, function (request, reply) {
@@ -162,7 +161,7 @@ This function will compile a validation schema and
162
161
  return a function that can be used to validate data.
163
162
  The function returned (a.k.a. _validation function_) is compiled
164
163
  by using the provided [`SchemaController#ValidationCompiler`](./Server.md#schema-controller).
165
- A `WeakMap` is used to cached this, reducing compilation calls.
164
+ A `WeakMap` is used to cache this, reducing compilation calls.
166
165
 
167
166
  The optional parameter `httpPart`, if provided, is forwarded directly
168
167
  the `ValidationCompiler`, so it can be used to compile the validation
@@ -567,7 +567,7 @@ const fastify = Fastify({ trustProxy: true })
567
567
  ```
568
568
 
569
569
  For more examples, refer to the
570
- [`proxy-addr`](https://www.npmjs.com/package/proxy-addr) package.
570
+ [`@fastify/proxy-addr`](https://www.npmjs.com/package/@fastify/proxy-addr) package.
571
571
 
572
572
  You may access the `ip`, `ips`, `host` and `protocol` values on the
573
573
  [`request`](./Request.md) object.
package/fastify.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const VERSION = '5.2.0'
3
+ const VERSION = '5.2.1'
4
4
 
5
5
  const Avvio = require('avvio')
6
6
  const http = require('node:http')
package/lib/errors.js CHANGED
@@ -241,6 +241,10 @@ const codes = {
241
241
  'FST_ERR_REP_RESPONSE_BODY_CONSUMED',
242
242
  'Response.body is already consumed.'
243
243
  ),
244
+ FST_ERR_REP_READABLE_STREAM_LOCKED: createError(
245
+ 'FST_ERR_REP_READABLE_STREAM_LOCKED',
246
+ 'ReadableStream was locked. You should call releaseLock() method on reader before sending.'
247
+ ),
244
248
  FST_ERR_REP_ALREADY_SENT: createError(
245
249
  'FST_ERR_REP_ALREADY_SENT',
246
250
  'Reply was already sent, did you forget to "return reply" in "%s" (%s)?'
package/lib/reply.js CHANGED
@@ -45,6 +45,7 @@ const CONTENT_TYPE = {
45
45
  const {
46
46
  FST_ERR_REP_INVALID_PAYLOAD_TYPE,
47
47
  FST_ERR_REP_RESPONSE_BODY_CONSUMED,
48
+ FST_ERR_REP_READABLE_STREAM_LOCKED,
48
49
  FST_ERR_REP_ALREADY_SENT,
49
50
  FST_ERR_SEND_INSIDE_ONERR,
50
51
  FST_ERR_BAD_STATUS_CODE,
@@ -670,6 +671,9 @@ function logStreamError (logger, err, res) {
670
671
  }
671
672
 
672
673
  function sendWebStream (payload, res, reply) {
674
+ if (payload.locked) {
675
+ throw FST_ERR_REP_READABLE_STREAM_LOCKED()
676
+ }
673
677
  const nodeStream = Readable.fromWeb(payload)
674
678
  sendStream(nodeStream, res, reply)
675
679
  }
package/lib/request.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const proxyAddr = require('proxy-addr')
3
+ const proxyAddr = require('@fastify/proxy-addr')
4
4
  const {
5
5
  kHasBeenDecorated,
6
6
  kSchemaBody,
@@ -117,10 +117,12 @@ function buildRequestWithTrustProxy (R, trustProxy) {
117
117
  if (this.ip !== undefined && this.headers['x-forwarded-host']) {
118
118
  return getLastEntryInMultiHeaderValue(this.headers['x-forwarded-host'])
119
119
  }
120
- // the last fallback is used to support the following cases:
121
- // 1. support http.requireHostHeader === false
122
- // 2. support HTTP/1.0 without Host Header
123
- // 3. support headers schema which may remove the Host Header
120
+ /**
121
+ * The last fallback supports the following cases:
122
+ * 1. http.requireHostHeader === false
123
+ * 2. HTTP/1.0 without a Host Header
124
+ * 3. Headers schema that may remove the Host Header
125
+ */
124
126
  return this.headers.host ?? this.headers[':authority'] ?? ''
125
127
  }
126
128
  },
@@ -213,10 +215,12 @@ Object.defineProperties(Request.prototype, {
213
215
  },
214
216
  host: {
215
217
  get () {
216
- // the last fallback is used to support the following cases:
217
- // 1. support http.requireHostHeader === false
218
- // 2. support HTTP/1.0 without Host Header
219
- // 3. support headers schema which may remove the Host Header
218
+ /**
219
+ * The last fallback supports the following cases:
220
+ * 1. http.requireHostHeader === false
221
+ * 2. HTTP/1.0 without a Host Header
222
+ * 3. Headers schema that may remove the Host Header
223
+ */
220
224
  return this.raw.headers.host ?? this.raw.headers[':authority'] ?? ''
221
225
  }
222
226
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "Fast and low overhead web framework, for Node.js",
5
5
  "main": "fastify.js",
6
6
  "type": "commonjs",
@@ -10,22 +10,22 @@
10
10
  "benchmark": "concurrently -k -s first \"node ./examples/benchmark/simple.js\" \"autocannon -c 100 -d 30 -p 10 localhost:3000/\"",
11
11
  "benchmark:parser": "concurrently -k -s first \"node ./examples/benchmark/parser.js\" \"autocannon -c 100 -d 30 -p 10 -i ./examples/benchmark/body.json -H \"content-type:application/jsoff\" -m POST localhost:3000/\"",
12
12
  "build:validation": "node build/build-error-serializer.js && node build/build-validation.js",
13
- "coverage": "c8 --reporter html borp --reporter=./test/test-reporter.mjs --coverage --check-coverage --lines 100 ",
14
- "coverage:ci-check-coverage": "borp --reporter=./test/test-reporter.mjs --coverage --check-coverage --lines 100",
13
+ "coverage": "c8 --reporter html borp --reporter=@jsumners/line-reporter --coverage --check-coverage --lines 100 ",
14
+ "coverage:ci-check-coverage": "borp --reporter=@jsumners/line-reporter --coverage --check-coverage --lines 100",
15
15
  "lint": "npm run lint:eslint",
16
16
  "lint:fix": "eslint --fix",
17
17
  "lint:markdown": "markdownlint-cli2",
18
18
  "lint:eslint": "eslint",
19
- "prepublishOnly": "cross-env PREPUBLISH=true borp --reporter=./test/test-reporter.mjs && npm run test:validator:integrity",
19
+ "prepublishOnly": "cross-env PREPUBLISH=true borp --reporter=@jsumners/line-reporter && npm run test:validator:integrity",
20
20
  "test": "npm run lint && npm run unit && npm run test:typescript",
21
21
  "test:ci": "npm run unit && npm run test:typescript",
22
22
  "test:report": "npm run lint && npm run unit:report && npm run test:typescript",
23
23
  "test:validator:integrity": "npm run build:validation && git diff --quiet --ignore-all-space --ignore-blank-lines --ignore-cr-at-eol lib/error-serializer.js && git diff --quiet --ignore-all-space --ignore-blank-lines --ignore-cr-at-eol lib/configValidator.js",
24
24
  "test:typescript": "tsc test/types/import.ts --target es2022 --moduleResolution node16 --module node16 --noEmit && tsd",
25
25
  "test:watch": "npm run unit -- --watch --coverage-report=none --reporter=terse",
26
- "unit": "borp --reporter=./test/test-reporter.mjs --coverage --check-coverage",
27
- "unit:report": "c8 --reporter html borp --reporter=./test/test-reporter.mjs",
28
- "citgm": "borp --reporter=./test/test-reporter.mjs --coverage --check-coverage --concurrency=1"
26
+ "unit": "borp --reporter=@jsumners/line-reporter --coverage --check-coverage",
27
+ "unit:report": "c8 --reporter html borp --reporter=@jsumners/line-reporter",
28
+ "citgm": "borp --reporter=@jsumners/line-reporter --coverage --check-coverage --concurrency=1"
29
29
  },
30
30
  "repository": {
31
31
  "type": "git",
@@ -131,6 +131,16 @@
131
131
  {
132
132
  "name": "Aras Abbasi",
133
133
  "email": "aras.abbasi@gmail.com"
134
+ },
135
+ {
136
+ "name": "Frazer Smith",
137
+ "email": "frazer.dev@icloud.com",
138
+ "url": "https://github.com/fdawgs"
139
+ },
140
+ {
141
+ "name": "KaKa Ng",
142
+ "email": "kaka@kakang.dev",
143
+ "url": "https://github.com/climba03003"
134
144
  }
135
145
  ],
136
146
  "license": "MIT",
@@ -150,6 +160,7 @@
150
160
  ],
151
161
  "devDependencies": {
152
162
  "@fastify/pre-commit": "^2.1.0",
163
+ "@jsumners/line-reporter": "^1.0.1",
153
164
  "@sinclair/typebox": "^0.33.4",
154
165
  "@sinonjs/fake-timers": "^11.2.2",
155
166
  "@stylistic/eslint-plugin": "^2.1.0",
@@ -191,6 +202,7 @@
191
202
  "@fastify/ajv-compiler": "^4.0.0",
192
203
  "@fastify/error": "^4.0.0",
193
204
  "@fastify/fast-json-stringify-compiler": "^5.0.0",
205
+ "@fastify/proxy-addr": "^5.0.0",
194
206
  "abstract-logging": "^2.0.1",
195
207
  "avvio": "^9.0.0",
196
208
  "fast-json-stringify": "^6.0.0",
@@ -198,7 +210,6 @@
198
210
  "light-my-request": "^6.0.0",
199
211
  "pino": "^9.0.0",
200
212
  "process-warning": "^4.0.0",
201
- "proxy-addr": "^2.0.7",
202
213
  "rfdc": "^1.3.1",
203
214
  "secure-json-parse": "^3.0.1",
204
215
  "semver": "^7.6.0",
@@ -1,9 +1,8 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
4
- const test = t.test
3
+ const { test } = require('node:test')
5
4
  const sget = require('simple-get').concat
6
- const Fastify = require('../fastify')
5
+ const Fastify = require('..')
7
6
  const { getServerUrl } = require('./helper')
8
7
 
9
8
  process.removeAllListeners('warning')
@@ -14,17 +13,17 @@ test('Wrong parseAs parameter', t => {
14
13
 
15
14
  try {
16
15
  fastify.addContentTypeParser('application/json', { parseAs: 'fireworks' }, () => {})
17
- t.fail('should throw')
16
+ t.assert.fail('should throw')
18
17
  } catch (err) {
19
- t.equal(err.code, 'FST_ERR_CTP_INVALID_PARSE_TYPE')
20
- t.equal(err.message, "The body parser can only parse your data as 'string' or 'buffer', you asked 'fireworks' which is not supported.")
18
+ t.assert.strictEqual(err.code, 'FST_ERR_CTP_INVALID_PARSE_TYPE')
19
+ t.assert.strictEqual(err.message, "The body parser can only parse your data as 'string' or 'buffer', you asked 'fireworks' which is not supported.")
21
20
  }
22
21
  })
23
22
 
24
- test('Should allow defining the bodyLimit per parser', t => {
23
+ test('Should allow defining the bodyLimit per parser', (t, done) => {
25
24
  t.plan(3)
26
25
  const fastify = Fastify()
27
- t.teardown(() => fastify.close())
26
+ t.after(() => fastify.close())
28
27
 
29
28
  fastify.post('/', (req, reply) => {
30
29
  reply.send(req.body)
@@ -34,13 +33,13 @@ test('Should allow defining the bodyLimit per parser', t => {
34
33
  'x/foo',
35
34
  { parseAs: 'string', bodyLimit: 5 },
36
35
  function (req, body, done) {
37
- t.fail('should not be invoked')
36
+ t.assert.fail('should not be invoked')
38
37
  done()
39
38
  }
40
39
  )
41
40
 
42
41
  fastify.listen({ port: 0 }, err => {
43
- t.error(err)
42
+ t.assert.ifError(err)
44
43
 
45
44
  sget({
46
45
  method: 'POST',
@@ -50,22 +49,22 @@ test('Should allow defining the bodyLimit per parser', t => {
50
49
  'Content-Type': 'x/foo'
51
50
  }
52
51
  }, (err, response, body) => {
53
- t.error(err)
54
- t.strictSame(JSON.parse(body.toString()), {
52
+ t.assert.ifError(err)
53
+ t.assert.deepStrictEqual(JSON.parse(body.toString()), {
55
54
  statusCode: 413,
56
55
  code: 'FST_ERR_CTP_BODY_TOO_LARGE',
57
56
  error: 'Payload Too Large',
58
57
  message: 'Request body is too large'
59
58
  })
60
- fastify.close()
59
+ done()
61
60
  })
62
61
  })
63
62
  })
64
63
 
65
- test('route bodyLimit should take precedence over a custom parser bodyLimit', t => {
64
+ test('route bodyLimit should take precedence over a custom parser bodyLimit', (t, done) => {
66
65
  t.plan(3)
67
66
  const fastify = Fastify()
68
- t.teardown(() => fastify.close())
67
+ t.after(() => fastify.close())
69
68
 
70
69
  fastify.post('/', { bodyLimit: 5 }, (request, reply) => {
71
70
  reply.send(request.body)
@@ -75,13 +74,13 @@ test('route bodyLimit should take precedence over a custom parser bodyLimit', t
75
74
  'x/foo',
76
75
  { parseAs: 'string', bodyLimit: 100 },
77
76
  function (req, body, done) {
78
- t.fail('should not be invoked')
77
+ t.assert.fail('should not be invoked')
79
78
  done()
80
79
  }
81
80
  )
82
81
 
83
82
  fastify.listen({ port: 0 }, err => {
84
- t.error(err)
83
+ t.assert.ifError(err)
85
84
 
86
85
  sget({
87
86
  method: 'POST',
@@ -89,14 +88,14 @@ test('route bodyLimit should take precedence over a custom parser bodyLimit', t
89
88
  body: '1234567890',
90
89
  headers: { 'Content-Type': 'x/foo' }
91
90
  }, (err, response, body) => {
92
- t.error(err)
93
- t.strictSame(JSON.parse(body.toString()), {
91
+ t.assert.ifError(err)
92
+ t.assert.deepStrictEqual(JSON.parse(body.toString()), {
94
93
  statusCode: 413,
95
94
  code: 'FST_ERR_CTP_BODY_TOO_LARGE',
96
95
  error: 'Payload Too Large',
97
96
  message: 'Request body is too large'
98
97
  })
99
- fastify.close()
98
+ done()
100
99
  })
101
100
  })
102
101
  })