Skip to content

Commit

Permalink
Merge branch 'main' into addHttpMethod-type-signature
Browse files Browse the repository at this point in the history
  • Loading branch information
kalvenschraut authored Nov 8, 2024
2 parents 9eab296 + 3ac4322 commit 7ab0646
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 75 deletions.
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ the following tasks:
[team.yml](https://github.com/fastify/website/blob/HEAD/static/data/team.yml)
file. This list is also sorted alphabetically so make sure to add your name
in the proper order. Use your GitHub profile icon for the `picture:` field.
5. The person that does the onboarding must add you to the [npm
5. Read the [pinned announcements](https://github.com/orgs/fastify/discussions/categories/announcements)
to be updated with the organisation’s news.
6. The person that does the onboarding must add you to the [npm
org](https://www.npmjs.com/org/fastify), so that you can help maintaining the
official plugins.
6. Optionally, the person can be added as an Open Collective member
7. Optionally, the person can be added as an Open Collective member
by the lead team.

### Offboarding Collaborators
Expand Down
4 changes: 4 additions & 0 deletions docs/Guides/Ecosystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ section.
- [`@ethicdevs/fastify-git-server`](https://github.com/EthicDevs/fastify-git-server)
A plugin to easily create git server and make one/many Git repositories available
for clone/fetch/push through the standard `git` (over http) commands.
- [`@exortek/fastify-mongo-sanitize`](https://github.com/ExorTek/fastify-mongo-sanitize)
A Fastify plugin that protects against No(n)SQL injection by sanitizing data.
- [`@exortek/remix-fastify`](https://github.com/ExorTek/remix-fastify)
Fastify plugin for Remix.
- [`@fastify-userland/request-id`](https://github.com/fastify-userland/request-id)
Fastify Request ID Plugin
- [`@fastify-userland/typeorm-query-runner`](https://github.com/fastify-userland/typeorm-query-runner)
Expand Down
13 changes: 7 additions & 6 deletions docs/Reference/Reply.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
- [.headers(object)](#headersobject)
- [.getHeader(key)](#getheaderkey)
- [.getHeaders()](#getheaders)
- [set-cookie](#set-cookie)
- [.removeHeader(key)](#removeheaderkey)
- [.hasHeader(key)](#hasheaderkey)
- [.writeEarlyHints(hints, callback)](#writeearlyhintshints-callback)
- [.trailer(key, function)](#trailerkey-function)
- [.hasTrailer(key)](#hastrailerkey)
- [.removeTrailer(key)](#removetrailerkey)
Expand All @@ -32,8 +32,9 @@
- [Strings](#strings)
- [Streams](#streams)
- [Buffers](#buffers)
- [ReadableStream](#send-readablestream)
- [Response](#send-response)
- [TypedArrays](#typedarrays)
- [ReadableStream](#readablestream)
- [Response](#response)
- [Errors](#errors)
- [Type of the final payload](#type-of-the-final-payload)
- [Async-Await and Promises](#async-await-and-promises)
Expand Down Expand Up @@ -87,7 +88,7 @@ since the request was received by Fastify.
already been called.
- `.hijack()` - interrupt the normal request lifecycle.
- `.raw` - The
[`http.ServerResponse`](https://nodejs.org/dist/latest-v14.x/docs/api/http.html#http_class_http_serverresponse)
[`http.ServerResponse`](https://nodejs.org/dist/latest-v20.x/docs/api/http.html#http_class_http_serverresponse)
from Node core.
- `.log` - The logger instance of the incoming request.
- `.request` - The incoming request.
Expand Down Expand Up @@ -157,7 +158,7 @@ Sets a response header. If the value is omitted or undefined, it is coerced to
> will result in a 500 `TypeError` response.
For more information, see
[`http.ServerResponse#setHeader`](https://nodejs.org/dist/latest-v14.x/docs/api/http.html#http_response_setheader_name_value).
[`http.ServerResponse#setHeader`](https://nodejs.org/dist/latest-v20.x/docs/api/http.html#http_response_setheader_name_value).

- ### set-cookie
<a id="set-cookie"></a>
Expand Down Expand Up @@ -586,7 +587,7 @@ values.
<a id="raw"></a>

This is the
[`http.ServerResponse`](https://nodejs.org/dist/latest-v14.x/docs/api/http.html#http_class_http_serverresponse)
[`http.ServerResponse`](https://nodejs.org/dist/latest-v20.x/docs/api/http.html#http_class_http_serverresponse)
from Node core. Whilst you are using the Fastify `Reply` object, the use of
`Reply.raw` functions is at your own risk as you are skipping all the Fastify
logic of handling the HTTP response. e.g.:
Expand Down
22 changes: 13 additions & 9 deletions docs/Reference/Server.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describes the properties available in that options object.
- [`onProtoPoisoning`](#onprotopoisoning)
- [`onConstructorPoisoning`](#onconstructorpoisoning)
- [`logger`](#logger)
- [`loggerInstance`](#loggerInstance)
- [`disableRequestLogging`](#disablerequestlogging)
- [`serverFactory`](#serverfactory)
- [`caseSensitive`](#casesensitive)
Expand Down Expand Up @@ -105,7 +106,7 @@ describes the properties available in that options object.

An object used to configure the server's listening socket. The options
are the same as the Node.js core [`createServer`
method](https://nodejs.org/dist/latest-v14.x/docs/api/http.html#http_http_createserver_options_requestlistener).
method](https://nodejs.org/docs/latest-v20.x/api/http.html#httpcreateserveroptions-requestlistener).

This option is ignored if options [`http2`](#factory-http2) or
[`https`](#factory-https) are set.
Expand All @@ -116,7 +117,7 @@ This option is ignored if options [`http2`](#factory-http2) or
+ Default: `false`

If `true` Node.js core's
[HTTP/2](https://nodejs.org/dist/latest-v14.x/docs/api/http2.html) module is
[HTTP/2](https://nodejs.org/dist/latest-v20.x/docs/api/http2.html) module is
used for binding the socket.

### `https`
Expand All @@ -126,7 +127,7 @@ used for binding the socket.

An object used to configure the server's listening socket for TLS. The options
are the same as the Node.js core [`createServer`
method](https://nodejs.org/dist/latest-v14.x/docs/api/https.html#https_https_createserver_options_requestlistener).
method](https://nodejs.org/dist/latest-v20.x/docs/api/https.html#https_https_createserver_options_requestlistener).
When this property is `null`, the socket will not be configured for TLS.

This option also applies when the [`http2`](#factory-http2) option is set.
Expand Down Expand Up @@ -329,9 +330,6 @@ The possible values this property may have are:
+ Default: `false`. The logger is disabled. All logging methods will point to a
null logger [abstract-logging](https://npm.im/abstract-logging) instance.

+ `pinoInstance`: a previously instantiated instance of Pino. The internal
logger will point to this instance.

+ `object`: a standard Pino [options
object](https://github.com/pinojs/pino/blob/c77d8ec5ce/docs/API.md#constructor).
This will be passed directly to the Pino constructor. If the following
Expand All @@ -351,9 +349,15 @@ The possible values this property may have are:
```
Any user-supplied serializer will override the default serializer of the
corresponding property.
+ `loggerInstance`: a custom logger instance. The logger must conform to the
Pino interface by having the following methods: `info`, `error`, `debug`,
`fatal`, `warn`, `trace`, `child`. For example:

### `loggerInstance`
<a id="factory-logger-instance"></a>

+ Default: `null`

A custom logger instance. The logger must be a Pino instance or conform to the
Pino interface by having the following methods: `info`, `error`, `debug`,
`fatal`, `warn`, `trace`, `child`. For example:
```js
const pino = require('pino')();
Expand Down
16 changes: 8 additions & 8 deletions test/encapsulated-child-logger-factory.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const Fastify = require('..')
const fp = require('fastify-plugin')

Expand All @@ -12,7 +12,7 @@ test('encapsulates an child logger factory', async t => {
fastify.setChildLoggerFactory(function pluginFactory (logger, bindings, opts) {
const child = logger.child(bindings, opts)
child.customLog = function (message) {
t.equal(message, 'custom')
t.assert.strictEqual(message, 'custom')
}
return child
})
Expand All @@ -24,7 +24,7 @@ test('encapsulates an child logger factory', async t => {
fastify.setChildLoggerFactory(function globalFactory (logger, bindings, opts) {
const child = logger.child(bindings, opts)
child.globalLog = function (message) {
t.equal(message, 'global')
t.assert.strictEqual(message, 'global')
}
return child
})
Expand All @@ -33,10 +33,10 @@ test('encapsulates an child logger factory', async t => {
})

const res1 = await fastify.inject('/encapsulated')
t.equal(res1.statusCode, 200)
t.assert.strictEqual(res1.statusCode, 200)

const res2 = await fastify.inject('/not-encapsulated')
t.equal(res2.statusCode, 200)
t.assert.strictEqual(res2.statusCode, 200)
})

test('child logger factory set on root scope when using fastify-plugin', async t => {
Expand All @@ -48,7 +48,7 @@ test('child logger factory set on root scope when using fastify-plugin', async t
fastify.setChildLoggerFactory(function pluginFactory (logger, bindings, opts) {
const child = logger.child(bindings, opts)
child.customLog = function (message) {
t.equal(message, 'custom')
t.assert.strictEqual(message, 'custom')
}
return child
})
Expand All @@ -62,8 +62,8 @@ test('child logger factory set on root scope when using fastify-plugin', async t
})

const res1 = await fastify.inject('/not-encapsulated-1')
t.equal(res1.statusCode, 200)
t.assert.strictEqual(res1.statusCode, 200)

const res2 = await fastify.inject('/not-encapsulated-2')
t.equal(res2.statusCode, 200)
t.assert.strictEqual(res2.statusCode, 200)
})
18 changes: 9 additions & 9 deletions test/listen.5.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const net = require('node:net')
const Fastify = require('../fastify')
const { once } = require('node:events')
Expand All @@ -26,9 +26,9 @@ test('same port conflict and success should not fire callback multiple times - c
switch (count) {
case 6: {
// success in here
t.error(err)
t.assert.ifError(err)
fastify.close((err) => {
t.error(err)
t.assert.ifError(err)
promise.resolve()
})
break
Expand All @@ -42,7 +42,7 @@ test('same port conflict and success should not fire callback multiple times - c
}
default: {
// expect error
t.equal(err.code, 'EADDRINUSE')
t.assert.strictEqual(err.code, 'EADDRINUSE')
setTimeout(() => {
fastify.listen(option, callback)
}, 100)
Expand All @@ -65,27 +65,27 @@ test('same port conflict and success should not fire callback multiple times - p
try {
await fastify.listen(option)
} catch (err) {
t.equal(err.code, 'EADDRINUSE')
t.assert.strictEqual(err.code, 'EADDRINUSE')
}
try {
await fastify.listen(option)
} catch (err) {
t.equal(err.code, 'EADDRINUSE')
t.assert.strictEqual(err.code, 'EADDRINUSE')
}
try {
await fastify.listen(option)
} catch (err) {
t.equal(err.code, 'EADDRINUSE')
t.assert.strictEqual(err.code, 'EADDRINUSE')
}
try {
await fastify.listen(option)
} catch (err) {
t.equal(err.code, 'EADDRINUSE')
t.assert.strictEqual(err.code, 'EADDRINUSE')
}
try {
await fastify.listen(option)
} catch (err) {
t.equal(err.code, 'EADDRINUSE')
t.assert.strictEqual(err.code, 'EADDRINUSE')
}

server.close()
Expand Down
27 changes: 16 additions & 11 deletions test/post-empty-body.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { test } = require('tap')
const fastify = require('../')
const { test } = require('node:test')
const Fastify = require('..')
const { request, setGlobalDispatcher, Agent } = require('undici')

setGlobalDispatcher(new Agent({
Expand All @@ -10,22 +10,27 @@ setGlobalDispatcher(new Agent({
}))

test('post empty body', async t => {
const app = fastify()
t.teardown(app.close.bind(app))

app.post('/bug', async (request, reply) => {
const fastify = Fastify()
const abortController = new AbortController()
const { signal } = abortController
t.after(() => {
fastify.close()
abortController.abort()
})

await app.listen({ port: 0 })
fastify.post('/bug', async (request, reply) => {})

await fastify.listen({ port: 0 })

const res = await request(`http://127.0.0.1:${app.server.address().port}/bug`, {
const res = await request(`http://127.0.0.1:${fastify.server.address().port}/bug`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ foo: 'bar' })
body: JSON.stringify({ foo: 'bar' }),
signal
})

t.equal(res.statusCode, 200)
t.equal(await res.body.text(), '')
t.assert.strictEqual(res.statusCode, 200)
t.assert.strictEqual(await res.body.text(), '')
})
Loading

0 comments on commit 7ab0646

Please sign in to comment.