Skip to content

Commit 6e98c95

Browse files
authored
docs(reference): mimic github notes and warning style (fastify#5973)
1 parent e2c367d commit 6e98c95

9 files changed

+82
-81
lines changed

docs/Reference/ContentTypeParser.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Note that for `GET` and `HEAD` requests, the payload is never parsed. For
2323
[catch-all](#catch-all) parser is not executed, and the payload is simply not
2424
parsed.
2525

26-
> ## ⚠ Security Notice
26+
> ⚠ Warning:
2727
> When using regular expressions to detect `Content-Type`, it is important to
2828
> ensure proper detection. For example, to match `application/*`, use
2929
> `/^application\/([\w-]+);?/` to match the
@@ -152,8 +152,8 @@ fastify.addContentTypeParser('text/xml', function (request, payload, done) {
152152
})
153153
```
154154

155-
**Notice**: `function(req, done)` and `async function(req)` are
156-
still supported but deprecated.
155+
> 🛈 Note: `function(req, done)` and `async function(req)` are
156+
> still supported but deprecated.
157157
158158
#### Body Parser
159159
The request body can be parsed in two ways. First, add a custom content type

docs/Reference/Hooks.md

+31-30
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ are Request/Reply hooks and application hooks:
3434
- [Using Hooks to Inject Custom Properties](#using-hooks-to-inject-custom-properties)
3535
- [Diagnostics Channel Hooks](#diagnostics-channel-hooks)
3636

37-
**Notice:** the `done` callback is not available when using `async`/`await` or
38-
returning a `Promise`. If you do invoke a `done` callback in this situation
39-
unexpected behavior may occur, e.g. duplicate invocation of handlers.
37+
> 🛈 Note: The `done` callback is not available when using `async`/`await` or
38+
> returning a `Promise`. If you do invoke a `done` callback in this situation
39+
> unexpected behavior may occur, e.g. duplicate invocation of handlers.
4040
4141
## Request/Reply Hooks
4242

@@ -68,9 +68,9 @@ fastify.addHook('onRequest', async (request, reply) => {
6868
})
6969
```
7070

71-
**Notice:** in the [onRequest](#onrequest) hook, `request.body` will always be
72-
`undefined`, because the body parsing happens before the
73-
[preValidation](#prevalidation) hook.
71+
> 🛈 Note: In the [onRequest](#onrequest) hook, `request.body` will always be
72+
> `undefined`, because the body parsing happens before the
73+
> [preValidation](#prevalidation) hook.
7474
7575
### preParsing
7676

@@ -98,17 +98,17 @@ fastify.addHook('preParsing', async (request, reply, payload) => {
9898
})
9999
```
100100

101-
**Notice:** in the [preParsing](#preparsing) hook, `request.body` will always be
102-
`undefined`, because the body parsing happens before the
103-
[preValidation](#prevalidation) hook.
101+
> 🛈 Note: In the [preParsing](#preparsing) hook, `request.body` will always be
102+
> `undefined`, because the body parsing happens before the
103+
> [preValidation](#prevalidation) hook.
104104
105-
**Notice:** you should also add a `receivedEncodedLength` property to the
106-
returned stream. This property is used to correctly match the request payload
107-
with the `Content-Length` header value. Ideally, this property should be updated
108-
on each received chunk.
105+
> 🛈 Note: You should also add a `receivedEncodedLength` property to the
106+
> returned stream. This property is used to correctly match the request payload
107+
> with the `Content-Length` header value. Ideally, this property should be updated
108+
> on each received chunk.
109109
110-
**Notice:** The size of the returned stream is checked to not exceed the limit
111-
set in [`bodyLimit`](./Server.md#bodylimit) option.
110+
> 🛈 Note: The size of the returned stream is checked to not exceed the limit
111+
> set in [`bodyLimit`](./Server.md#bodylimit) option.
112112
113113
### preValidation
114114

@@ -166,8 +166,8 @@ fastify.addHook('preSerialization', async (request, reply, payload) => {
166166
})
167167
```
168168

169-
Note: the hook is NOT called if the payload is a `string`, a `Buffer`, a
170-
`stream`, or `null`.
169+
> 🛈 Note: The hook is NOT called if the payload is a `string`, a `Buffer`, a
170+
> `stream`, or `null`.
171171
172172
### onError
173173
```js
@@ -196,8 +196,8 @@ user
196196
*(Note that the default error handler always sends the error back to the
197197
user)*.
198198

199-
**Notice:** unlike the other hooks, passing an error to the `done` function is not
200-
supported.
199+
> 🛈 Note: Unlike the other hooks, passing an error to the `done` function is not
200+
> supported.
201201
202202
### onSend
203203
If you are using the `onSend` hook, you can change the payload. For example:
@@ -233,8 +233,8 @@ fastify.addHook('onSend', (request, reply, payload, done) => {
233233
> to `0`, whereas the `Content-Length` header will not be set if the payload is
234234
> `null`.
235235
236-
Note: If you change the payload, you may only change it to a `string`, a
237-
`Buffer`, a `stream`, a `ReadableStream`, a `Response`, or `null`.
236+
> 🛈 Note: If you change the payload, you may only change it to a `string`, a
237+
> `Buffer`, a `stream`, a `ReadableStream`, a `Response`, or `null`.
238238
239239

240240
### onResponse
@@ -256,8 +256,8 @@ The `onResponse` hook is executed when a response has been sent, so you will not
256256
be able to send more data to the client. It can however be useful for sending
257257
data to external services, for example, to gather statistics.
258258

259-
**Note:** setting `disableRequestLogging` to `true` will disable any error log
260-
inside the `onResponse` hook. In this case use `try - catch` to log errors.
259+
> 🛈 Note: Setting `disableRequestLogging` to `true` will disable any error log
260+
> inside the `onResponse` hook. In this case use `try - catch` to log errors.
261261
262262
### onTimeout
263263

@@ -298,7 +298,8 @@ The `onRequestAbort` hook is executed when a client closes the connection before
298298
the entire request has been processed. Therefore, you will not be able to send
299299
data to the client.
300300

301-
**Notice:** client abort detection is not completely reliable. See: [`Detecting-When-Clients-Abort.md`](../Guides/Detecting-When-Clients-Abort.md)
301+
> 🛈 Note: Client abort detection is not completely reliable.
302+
> See: [`Detecting-When-Clients-Abort.md`](../Guides/Detecting-When-Clients-Abort.md)
302303
303304
### Manage Errors from a hook
304305
If you get an error during the execution of your hook, just pass it to `done()`
@@ -451,8 +452,8 @@ fastify.addHook('onListen', async function () {
451452
})
452453
```
453454

454-
> **Note**
455-
> This hook will not run when the server is started using `fastify.inject()` or `fastify.ready()`
455+
> 🛈 Note: This hook will not run when the server is started using
456+
> fastify.inject()` or `fastify.ready()`.
456457
457458
### onClose
458459
<a id="on-close"></a>
@@ -575,8 +576,8 @@ This hook can be useful if you are developing a plugin that needs to know when a
575576
plugin context is formed, and you want to operate in that specific context, thus
576577
this hook is encapsulated.
577578

578-
**Note:** This hook will not be called if a plugin is wrapped inside
579-
[`fastify-plugin`](https://github.com/fastify/fastify-plugin).
579+
> 🛈 Note: This hook will not be called if a plugin is wrapped inside
580+
> [`fastify-plugin`](https://github.com/fastify/fastify-plugin).
580581
```js
581582
fastify.decorate('data', [])
582583

@@ -773,7 +774,7 @@ fastify.route({
773774
})
774775
```
775776

776-
**Note**: both options also accept an array of functions.
777+
> 🛈 Note: Both options also accept an array of functions.
777778
778779
## Using Hooks to Inject Custom Properties
779780
<a id="using-hooks-to-inject-custom-properties"></a>
@@ -860,7 +861,7 @@ channel.subscribe(function ({ fastify }) {
860861
})
861862
```
862863
863-
> **Note:** The TracingChannel class API is currently experimental and may undergo
864+
> 🛈 Note: The TracingChannel class API is currently experimental and may undergo
864865
> breaking changes even in semver-patch releases of Node.js.
865866
866867
Five other events are published on a per-request basis following the

docs/Reference/Logging.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ const fastify = require('fastify')({
157157
});
158158
```
159159
160-
**Note**: In some cases, the [`Reply`](./Reply.md) object passed to the `res`
161-
serializer cannot be fully constructed. When writing a custom `res` serializer,
162-
check for the existence of any properties on `reply` aside from `statusCode`,
163-
which is always present. For example, verify the existence of `getHeaders`
164-
before calling it:
160+
> 🛈 Note: In some cases, the [`Reply`](./Reply.md) object passed to the `res`
161+
> serializer cannot be fully constructed. When writing a custom `res`
162+
> serializer, check for the existence of any properties on `reply` aside from
163+
> `statusCode`, which is always present. For example, verify the existence of
164+
> `getHeaders` before calling it:
165165
166166
```js
167167
const fastify = require('fastify')({
@@ -184,7 +184,7 @@ const fastify = require('fastify')({
184184
});
185185
```
186186
187-
**Note**: The body cannot be serialized inside a `req` method because the
187+
> 🛈 Note: The body cannot be serialized inside a `req` method because the
188188
request is serialized when the child logger is created. At that time, the body
189189
is not yet parsed.
190190
@@ -199,10 +199,10 @@ app.addHook('preHandler', function (req, reply, done) {
199199
})
200200
```
201201
202-
**Note**: Ensure serializers never throw errors, as this can cause the Node
203-
process to exit. See the
204-
[Pino documentation](https://getpino.io/#/docs/api?id=opt-serializers) for more
205-
information.
202+
> 🛈 Note: Ensure serializers never throw errors, as this can cause the Node
203+
> process to exit. See the
204+
> [Pino documentation](https://getpino.io/#/docs/api?id=opt-serializers) for more
205+
> information.
206206
207207
*Any logger other than Pino will ignore this option.*
208208

docs/Reference/Middleware.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ that already has the Fastify [Request](./Request.md#request) and
5050
To run middleware under certain paths, pass the path as the first parameter to
5151
`use`.
5252

53-
*Note: This does not support routes with parameters (e.g. `/user/:id/comments`)
54-
and wildcards are not supported in multiple paths.*
53+
> 🛈 Note: This does not support routes with parameters
54+
> (e.g. `/user/:id/comments`) and wildcards are not supported in multiple paths.
5555
5656
```js
5757
const path = require('node:path')

docs/Reference/Reply.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fastify.get('/', async function (req, rep) {
151151
Sets a response header. If the value is omitted or undefined, it is coerced to
152152
`''`.
153153

154-
> Note: the header's value must be properly encoded using
154+
> 🛈 Note: The header's value must be properly encoded using
155155
> [`encodeURI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
156156
> or similar modules such as
157157
> [`encodeurl`](https://www.npmjs.com/package/encodeurl). Invalid characters
@@ -260,11 +260,11 @@ requires heavy resources to be sent after the `data`, for example,
260260
`Server-Timing` and `Etag`. It can ensure the client receives the response data
261261
as soon as possible.
262262

263-
*Note: The header `Transfer-Encoding: chunked` will be added once you use the
264-
trailer. It is a hard requirement for using trailer in Node.js.*
263+
> 🛈 Note: The header `Transfer-Encoding: chunked` will be added once you use
264+
> the trailer. It is a hard requirement for using trailer in Node.js.
265265

266-
*Note: Any error passed to `done` callback will be ignored. If you interested
267-
in the error, you can turn on `debug` level logging.*
266+
> 🛈 Note: Any error passed to `done` callback will be ignored. If you interested
267+
> in the error, you can turn on `debug` level logging.*
268268

269269
```js
270270
reply.trailer('server-timing', function() {
@@ -314,7 +314,7 @@ reply.getTrailer('server-timing') // undefined
314314
Redirects a request to the specified URL, the status code is optional, default
315315
to `302` (if status code is not already set by calling `code`).
316316

317-
> Note: the input URL must be properly encoded using
317+
> 🛈 Note: The input URL must be properly encoded using
318318
> [`encodeURI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
319319
> or similar modules such as
320320
> [`encodeurl`](https://www.npmjs.com/package/encodeurl). Invalid URLs will
@@ -823,8 +823,8 @@ automatically create an error structured as the following:
823823
You can add custom properties to the Error object, such as `headers`, that will
824824
be used to enhance the HTTP response.
825825

826-
*Note: If you are passing an error to `send` and the statusCode is less than
827-
400, Fastify will automatically set it at 500.*
826+
> 🛈 Note: If you are passing an error to `send` and the statusCode is less than
827+
> 400, Fastify will automatically set it at 500.
828828
829829
Tip: you can simplify errors by using the
830830
[`http-errors`](https://npm.im/http-errors) module or
@@ -871,7 +871,7 @@ fastify.get('/', {
871871
If you want to customize error handling, check out
872872
[`setErrorHandler`](./Server.md#seterrorhandler) API.
873873

874-
*Note: you are responsible for logging when customizing the error handler*
874+
> 🛈 Note: you are responsible for logging when customizing the error handler.
875875
876876
API:
877877

docs/Reference/Request.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ This operation adds new values to the request headers, accessible via
8484
For performance reasons, `Symbol('fastify.RequestAcceptVersion')` may be added
8585
to headers on `not found` routes.
8686

87-
> Note: Schema validation may mutate the `request.headers` and
88-
`request.raw.headers` objects, causing the headers to become empty.
87+
> 🛈 Note: Schema validation may mutate the `request.headers` and
88+
> `request.raw.headers` objects, causing the headers to become empty.
8989
9090
```js
9191
fastify.post('/:params', options, function (request, reply) {

docs/Reference/Routes.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ fastify.get('/', options, async function (request, reply) {
376376
})
377377
```
378378

379-
**Warning:**
380-
* When using both `return value` and `reply.send(value)`, the first one takes
381-
precedence, the second is discarded, and a *warn* log is emitted.
382-
* Calling `reply.send()` outside of the promise is possible but requires special
383-
attention. See [promise-resolution](#promise-resolution).
384-
* `undefined` cannot be returned. See [promise-resolution](#promise-resolution).
379+
> Warning:
380+
> * When using both `return value` and `reply.send(value)`, the first one takes
381+
> precedence, the second is discarded, and a *warn* log is emitted.
382+
> * Calling `reply.send()` outside of the promise is possible but requires special
383+
> attention. See [promise-resolution](#promise-resolution).
384+
> * `undefined` cannot be returned. See [promise-resolution](#promise-resolution).
385385
386386
### Promise resolution
387387
<a id="promise-resolution"></a>
@@ -659,7 +659,7 @@ fastify.inject({
659659
})
660660
```
661661

662-
> ## ⚠ Security Notice
662+
> ⚠ Warning:
663663
> Set a
664664
> [`Vary`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary)
665665
> header in responses with the value used for versioning
@@ -771,7 +771,7 @@ const secret = {
771771
}
772772
```
773773

774-
> ## ⚠ Security Notice
774+
> ⚠ Warning:
775775
> When using asynchronous constraints, avoid returning errors inside the
776776
> callback. If errors are unavoidable, provide a custom `frameworkErrors`
777777
> handler to manage them. Otherwise, route selection may break or expose

0 commit comments

Comments
 (0)