Skip to content

Commit 9015e6e

Browse files
authored
Fix several broken links on website, clarify docs (fastify#2434)
1 parent 6233a8f commit 9015e6e

18 files changed

+104
-102
lines changed

docs/ContentTypeParser.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Natively, Fastify only supports `'application/json'` and `'text/plain'` content
55

66
As with the other APIs, `addContentTypeParser` is encapsulated in the scope in which it is declared. This means that if you declare it in the root scope it will be available everywhere, while if you declare it inside a plugin it will be available only in that scope and its children.
77

8-
Fastify automatically adds the parsed request payload to the [Fastify request](./Request.md) object which you can access with `request.body`.
8+
Fastify automatically adds the parsed request payload to the [Fastify request](Request.md) object which you can access with `request.body`.
99

1010
### Usage
1111
```js
@@ -45,7 +45,7 @@ if (!fastify.hasContentTypeParser('application/jsoff')){
4545
**Notice**: The old syntaxes `function(req, done)` and `async function(req)` for the parser are still supported but they are deprecated.
4646

4747
#### Body Parser
48-
You can parse the body of a request in two ways. The first one is shown above: you add a custom content type parser and handle the request stream. In the second one, you should pass a `parseAs` option to the `addContentTypeParser` API, where you declare how you want to get the body. It could be of type `'string'` or `'buffer'`. If you use the `parseAs` option, Fastify will internally handle the stream and perform some checks, such as the [maximum size](./Server.md#factory-body-limit) of the body and the content length. If the limit is exceeded the custom parser will not be invoked.
48+
You can parse the body of a request in two ways. The first one is shown above: you add a custom content type parser and handle the request stream. In the second one, you should pass a `parseAs` option to the `addContentTypeParser` API, where you declare how you want to get the body. It could be of type `'string'` or `'buffer'`. If you use the `parseAs` option, Fastify will internally handle the stream and perform some checks, such as the [maximum size](Server.md#factory-body-limit) of the body and the content length. If the limit is exceeded the custom parser will not be invoked.
4949
```js
5050
fastify.addContentTypeParser('application/json', { parseAs: 'string' }, function (req, body, done) {
5151
try {
@@ -62,7 +62,7 @@ See [`example/parser.js`](../examples/parser.js) for an example.
6262

6363
##### Custom Parser Options
6464
+ `parseAs` (string): Either `'string'` or `'buffer'` to designate how the incoming data should be collected. Default: `'buffer'`.
65-
+ `bodyLimit` (number): The maximum payload size, in bytes, that the custom parser will accept. Defaults to the global body limit passed to the [`Fastify factory function`](./Server.md#bodylimit).
65+
+ `bodyLimit` (number): The maximum payload size, in bytes, that the custom parser will accept. Defaults to the global body limit passed to the [`Fastify factory function`](Server.md#bodylimit).
6666

6767
#### Catch-All
6868
There are some cases where you need to catch all requests regardless of their content type. With Fastify, you can just use the `'*'` content type.
@@ -113,4 +113,4 @@ fastify.route({
113113
})
114114
```
115115

116-
For piping file uploads you may want to checkout [this plugin](https://github.com/fastify/fastify-multipart).
116+
For piping file uploads you may want to checkout [this plugin](https://github.com/fastify/fastify-multipart).

docs/Decorators.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fastify.utility()
9393
console.log(fastify.conf.db)
9494
```
9595

96-
The decorated [Fastify server](./Server.md) is bound to `this` in route [route](./Routes.md) handlers:
96+
The decorated [Fastify server](Server.md) is bound to `this` in route [route](Routes.md) handlers:
9797

9898
```js
9999
fastify.decorate('db', new DbConnection())

docs/Errors.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
Uncaught errors are likely to cause memory leaks, file descriptor leaks and other major production issues. [Domains](https://nodejs.org/en/docs/guides/domain-postmortem/) were introduced to try fixing this issue, but they did not. Given the fact that it is not possible to process all uncaught errors sensibly, the best way to deal with them at the moment is to [crash](https://nodejs.org/api/process.html#process_warning_using_uncaughtexception_correctly). In case of promises, make sure to [handle](https://nodejs.org/dist/latest-v8.x/docs/api/deprecations.html#deprecations_dep0018_unhandled_promise_rejections) errors [correctly](https://github.com/mcollina/make-promises-safe).
1010

11-
Fastify follows an all-or-nothing approach and aims to be lean and optimal as much as possible. Thus, the developer is responsible for making sure that the errors are handled properly. Most of the errors are usually a result of unexpected input data, so we recommend specifying a [JSON.schema validation](./Validation-and-Serialization.md) for your input data.
11+
Fastify follows an all-or-nothing approach and aims to be lean and optimal as much as possible. Thus, the developer is responsible for making sure that the errors are handled properly. Most of the errors are usually a result of unexpected input data, so we recommend specifying a [JSON.schema validation](Validation-and-Serialization.md) for your input data.
1212

1313
Fastify tries to catch as many uncaught errors it can without hindering performance. This includes:
1414

1515
1. synchronous routes, e.g. `app.get('/', () => { throw new Error('kaboom') })`
1616
2. `async` routes, e.g. `app.get('/', async () => { throw new Error('kaboom') })`
1717

18-
In those two cases, the error will safely be caught by the promise and routed to the default error handler of Fastify for a generic `Internal Server Error` response. For customizing this behaviour, you should use [`setErrorHandler`](./Server.md#seterrorhandler).
18+
In those two cases, the error will safely be caught by the promise and routed to the default error handler of Fastify for a generic `Internal Server Error` response. For customizing this behaviour, you should use [`setErrorHandler`](Server.md#seterrorhandler).
1919

2020
<a name="fastify-error-codes"></a>
2121
### Fastify Error Codes

docs/Fluent-Schema.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Fluent Schema
44

5-
The [Validation and Serialization](./Validation-and-Serialization.md) documentation outlines all parameters accepted by Fastify to set up JSON Schema Validation in order to validate the input, and JSON Schema Serialization in order to optimize the output.
5+
The [Validation and Serialization](Validation-and-Serialization.md) documentation outlines all parameters accepted by Fastify to set up JSON Schema Validation in order to validate the input, and JSON Schema Serialization in order to optimize the output.
66

77
[`fluent-schema`](https://github.com/fastify/fluent-schema) can be used to simplify this task while allowing the reuse of constants.
88

@@ -53,7 +53,7 @@ fastify.post('/the/url', { schema }, handler)
5353

5454
With `fluent-schema` you can manipulate your schemas in an easier and programmatic way and then reuse them
5555
thanks to the `addSchema()` method. You can refer to the schema in two different manners that are detailed
56-
in the [Validation-and-Serialization.md](./Validation-and-Serialization.md#adding-a-shared-schema) documentation.
56+
in the [Validation-and-Serialization.md](Validation-and-Serialization.md#adding-a-shared-schema) documentation.
5757

5858
Here are some usage examples:
5959

docs/Getting-Started.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Fastify offers an easy platform that helps to solve all of the problems outlined
8585
### Your first plugin
8686
As with JavaScript, where everything is an object, with Fastify everything is a plugin.<br>
8787
Before digging into it, let's see how it works!<br>
88-
Let's declare our basic server, but instead of declaring the route inside the entry point, we'll declare it in an external file (check out the [route declaration](./Routes.md) docs).
88+
Let's declare our basic server, but instead of declaring the route inside the entry point, we'll declare it in an external file (check out the [route declaration](Routes.md) docs).
8989
```js
9090
const fastify = require('fastify')({
9191
logger: true
@@ -195,12 +195,12 @@ module.exports = routes
195195
Wow, that was fast!<br>
196196
Let's recap what we have done here since we've introduced some new concepts.<br>
197197
As you can see, we used `register` both for the database connector and the registration of the routes.
198-
This is one of the best features of Fastify, it will load your plugins in the same order you declare them, and it will load the next plugin only once the current one has been loaded. In this way, we can register the database connector in the first plugin and use it in the second *(read [here](./Plugins.md#handle-the-scope) to understand how to handle the scope of a plugin)*.
198+
This is one of the best features of Fastify, it will load your plugins in the same order you declare them, and it will load the next plugin only once the current one has been loaded. In this way, we can register the database connector in the first plugin and use it in the second *(read [here](Plugins.md#handle-the-scope) to understand how to handle the scope of a plugin)*.
199199
Plugin loading starts when you call `fastify.listen()`, `fastify.inject()` or `fastify.ready()`
200200

201201
We have also used the `decorate` API to add custom objects to the Fastify namespace, making them available for use everywhere. Use of this API is encouraged to facilitate easy code reuse and to decrease code or logic duplication.
202202

203-
To dig deeper into how Fastify plugins work, how to develop new plugins, and for details on how to use the whole Fastify API to deal with the complexity of asynchronously bootstrapping an application, read [the hitchhiker's guide to plugins](./Plugins-Guide.md).
203+
To dig deeper into how Fastify plugins work, how to develop new plugins, and for details on how to use the whole Fastify API to deal with the complexity of asynchronously bootstrapping an application, read [the hitchhiker's guide to plugins](Plugins-Guide.md).
204204

205205
<a name="plugin-loading-order"></a>
206206
### Loading order of your plugins
@@ -259,7 +259,7 @@ fastify.post('/', opts, async (request, reply) => {
259259
})
260260
```
261261
This example shows how to pass an options object to the route, which accepts a `schema` key, that contains all of the schemas for route, `body`, `querystring`, `params` and `headers`.<br>
262-
Read [Validation and Serialization](./Validation-and-Serialization.md) to learn more.
262+
Read [Validation and Serialization](Validation-and-Serialization.md) to learn more.
263263

264264
<a name="serialize-data"></a>
265265
### Serialize your data
@@ -284,17 +284,17 @@ fastify.get('/', opts, async (request, reply) => {
284284
})
285285
```
286286
Simply by specifying a schema as shown, you can speed up serialization by a factor of 2-3. This also helps to protect against leakage of potentially sensitive data, since Fastify will serialize only the data present in the response schema.
287-
Read [Validation and Serialization](./Validation-and-Serialization.md) to learn more.
287+
Read [Validation and Serialization](Validation-and-Serialization.md) to learn more.
288288

289289
<a name="extend-server"></a>
290290
### Extend your server
291291
Fastify is built to be extremely extensible and minimal, we believe that a bare bones framework is all that is necessary to make great applications possible.<br>
292-
In other words, Fastify is not a "batteries included" framework, and relies on an amazing [ecosystem](./Ecosystem.md)!
292+
In other words, Fastify is not a "batteries included" framework, and relies on an amazing [ecosystem](Ecosystem.md)!
293293

294294
<a name="test-server"></a>
295295
### Test your server
296296
Fastify does not offer a testing framework, but we do recommend a way to write your tests that uses the features and architecture of Fastify.<br>
297-
Read the [testing](./Testing.md) documentation to learn more!
297+
Read the [testing](Testing.md) documentation to learn more!
298298

299299
<a name="cli"></a>
300300
### Run your server from CLI

docs/Hooks.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ By using hooks you can interact directly with the lifecycle of Fastify. There ar
2727

2828
## Request/Reply Hooks
2929

30-
[Request](./Request.md) and [Reply](./Reply.md) are the core Fastify objects.<br/>
31-
`done` is the function to continue with the [lifecycle](./Lifecycle.md).
30+
[Request](Request.md) and [Reply](Reply.md) are the core Fastify objects.<br/>
31+
`done` is the function to continue with the [lifecycle](Lifecycle.md).
3232

33-
It is pretty easy to understand where each hook is executed by looking at the [lifecycle page](./Lifecycle.md).<br>
33+
It is pretty easy to understand where each hook is executed by looking at the [lifecycle page](Lifecycle.md).<br>
3434
Hooks are affected by Fastify's encapsulation, and can thus be applied to selected routes. See the [Scopes](#scope) section for more information.
3535

3636
There are eight different hooks that you can use in Request/Reply *(in order of execution)*:
@@ -219,7 +219,7 @@ fastify.addHook('preHandler', (request, reply, done) => {
219219
done(new Error('Some error'))
220220
})
221221
```
222-
*The error will be handled by [`Reply`](./Reply.md#errors).*
222+
*The error will be handled by [`Reply`](Reply.md#errors).*
223223

224224
Or if you're using `async/await` you can just throw an error:
225225
```js
@@ -322,7 +322,7 @@ fastify.addHook('onReady', async function () {
322322

323323
<a name="on-close"></a>
324324
### onClose
325-
Triggered when `fastify.close()` is invoked to stop the server. It is useful when [plugins](./Plugins.md) need a "shutdown" event, for example to close an open connection to a database.<br>
325+
Triggered when `fastify.close()` is invoked to stop the server. It is useful when [plugins](Plugins.md) need a "shutdown" event, for example to close an open connection to a database.<br>
326326
The first argument is the Fastify instance, the second one the `done` callback.
327327
```js
328328
fastify.addHook('onClose', (instance, done) => {
@@ -396,7 +396,7 @@ fastify.addHook('onRegister', (instance, opts) => {
396396

397397
<a name="scope"></a>
398398
## Scope
399-
Except for [onClose](#onclose), all hooks are encapsulated. This means that you can decide where your hooks should run by using `register` as explained in the [plugins guide](./Plugins-Guide.md). If you pass a function, that function is bound to the right Fastify context and from there you have full access to the Fastify API.
399+
Except for [onClose](#onclose), all hooks are encapsulated. This means that you can decide where your hooks should run by using `register` as explained in the [plugins guide](Plugins-Guide.md). If you pass a function, that function is bound to the right Fastify context and from there you have full access to the Fastify API.
400400

401401
```js
402402
fastify.addHook('onRequest', function (request, reply, done) {

docs/Logging.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ const fastify = require('fastify')({
5757

5858
<a name="logging-request-id"></a>
5959

60-
By default, fastify adds an id to every request for easier tracking. If the "request-id" header is present its value is used, otherwise a new incremental id is generated. See Fastify Factory [`requestIdHeader`](./Server.md#factory-request-id-header) and Fastify Factory [`genReqId`](./Server.md#gen-request-id) for customization options.
60+
By default, fastify adds an id to every request for easier tracking. If the "request-id" header is present its value is used, otherwise a new incremental id is generated. See Fastify Factory [`requestIdHeader`](Server.md#factory-request-id-header) and Fastify Factory [`genReqId`](Server.md#gen-request-id) for customization options.
6161

62-
The default logger is configured with a set of standard serializers that serialize objects with `req`, `res`, and `err` properties. The object received by `req` is the Fastify [`Request`](./Request.md) object, while the object received by `res` is the Fastify [`Reply`](./Reply.md) object.
62+
The default logger is configured with a set of standard serializers that serialize objects with `req`, `res`, and `err` properties. The object received by `req` is the Fastify [`Request`](Request.md) object, while the object received by `res` is the Fastify [`Reply`](Reply.md) object.
6363
This behaviour can be customized by specifying custom serializers.
6464
```js
6565
const fastify = require('fastify')({
@@ -136,7 +136,7 @@ fastify.get('/', function (request, reply) {
136136
})
137137
```
138138

139-
*The logger instance for the current request is available in every part of the [lifecycle](./Lifecycle.md).*
139+
*The logger instance for the current request is available in every part of the [lifecycle](Lifecycle.md).*
140140

141141
## Log Redaction
142142

docs/Middleware.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ await fastify.register(require('middie'))
2323
fastify.use(require('cors')())
2424
```
2525

26-
Remember that middleware can be encapsulated, this means that you can decide where your middleware should run by using `register` as explained in the [plugins guide](./Plugins-Guide.md).
26+
Remember that middleware can be encapsulated, this means that you can decide where your middleware should run by using `register` as explained in the [plugins guide](Plugins-Guide.md).
2727

28-
Fastify middleware also do not expose the `send` method or other methods specific to the Fastify [Reply](./Reply.md#reply) instance. This is because Fastify wraps the incoming `req` and `res` Node instances using the [Request](./Request.md#request) and [Reply](./Reply.md#reply) objects internally, but this is done after the middleware phase. If you need to create middleware, you have to use the Node `req` and `res` instances. Otherwise, you can use the `preHandler` hook which already has the [Request](./Request.md#request) and [Reply](./Reply.md#reply) Fastify instances. For more information, see [Hooks](./Hooks.md#hooks).
28+
Fastify middleware also do not expose the `send` method or other methods specific to the Fastify [Reply](Reply.md#reply) instance. This is because Fastify wraps the incoming `req` and `res` Node instances using the [Request](Request.md#request) and [Reply](Reply.md#reply) objects internally, but this is done after the middleware phase. If you need to create middleware, you have to use the Node `req` and `res` instances. Otherwise, you can use the `preHandler` hook which already has the [Request](Request.md#request) and [Reply](Reply.md#reply) Fastify instances. For more information, see [Hooks](Hooks.md#hooks).
2929

3030
<a name="restrict-usage"></a>
3131
#### Restrict middleware execution to a certain path(s)
@@ -41,7 +41,7 @@ const serveStatic = require('serve-static')
4141
fastify.use('/css', serveStatic(path.join(__dirname, '/assets')))
4242

4343
// Wildcard path
44-
fastify.use('/css/*', serveStatic(path.join(__dirname, '/assets')))
44+
fastify.use('/css/(.*)', serveStatic(path.join(__dirname, '/assets')))
4545

4646
// Multiple paths
4747
fastify.use(['/css', '/js'], serveStatic(path.join(__dirname, '/assets')))

docs/Migration-Guide-V3.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ fastify.use(require('cors')());
3434

3535
### Changed logging serialization ([#2017](https://github.com/fastify/fastify/pull/2017))
3636

37-
The logging [Serializers](./Logging.md) have been updated to now Fastify
38-
[`Request`](./Request.md) and [`Reply`](./Reply.md) objects instead of
37+
The logging [Serializers](Logging.md) have been updated to now Fastify
38+
[`Request`](Request.md) and [`Reply`](Reply.md) objects instead of
3939
native ones.
4040

4141
Any custom serializers must be updated if they rely upon `request` or `reply`
@@ -269,14 +269,14 @@ fastify.get('/', (request, reply) => {
269269

270270
- Hooks now have consistent context irregardless of how they are registered
271271
([#2005](https://github.com/fastify/fastify/pull/2005))
272-
- Deprecated `request.req` and `reply.res` for [`request.raw`](./Request.md) and
273-
[`reply.raw`](./Reply.md) ([#2008](https://github.com/fastify/fastify/pull/2008))
272+
- Deprecated `request.req` and `reply.res` for [`request.raw`](Request.md) and
273+
[`reply.raw`](Reply.md) ([#2008](https://github.com/fastify/fastify/pull/2008))
274274
- Removed `modifyCoreObjects` option ([#2015](https://github.com/fastify/fastify/pull/2015))
275-
- Added [`connectionTimeout`](./Server.md#factory-connection-timeout)
275+
- Added [`connectionTimeout`](Server.md#factory-connection-timeout)
276276
option ([#2086](https://github.com/fastify/fastify/pull/2086))
277-
- Added [`keepAliveTimeout`](./Server.md#factory-keep-alive-timeout)
277+
- Added [`keepAliveTimeout`](Server.md#factory-keep-alive-timeout)
278278
option ([#2086](https://github.com/fastify/fastify/pull/2086))
279-
- Added async-await support for [plugins](./Plugins.md#async-await)
279+
- Added async-await support for [plugins](Plugins.md#async-await)
280280
([#2093](https://github.com/fastify/fastify/pull/2093))
281281
- Added the feature to throw object as error
282282
([#2134](https://github.com/fastify/fastify/pull/2134))

0 commit comments

Comments
 (0)