Skip to content

Commit

Permalink
Update Migration-Guide-V4.md (#4091)
Browse files Browse the repository at this point in the history
* Update Migration-Guide-V4.md

* Update docs/Guides/Migration-Guide-V4.md

Co-authored-by: Matteo Collina <matteo.collina@gmail.com>

* Update Migration-Guide-V4.md

Add code examples to the Synchronous route definitions section

* Update Migration-Guide-V4.md

* Fix doc linting

Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
denes-fekeshazy and mcollina committed Jun 28, 2022
1 parent 977dec0 commit 4eea272
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/Guides/Migration-Guide-V4.md
Expand Up @@ -65,6 +65,35 @@ Starting from v4, all the `GET` routes will create a sibling `HEAD` route.
You can revert this behaviour by setting the server's option `exposeHeadRoutes`
to `false`.

### Synchronous route definitions

The route registration has been made synchronous from v4.
This change was done to provide better error reporting for route definition.
As a result if you specify an `onRoute` hook in a plugin you should either:
* wrap your routes in a plugin (recommended)
* use `await register(...)`

For example refactor this:
```
fastify.register((instance, opts, done) => {
instance.addHook('onRoute', (routeOptions) => {
const { path, method } = routeOptions;
console.log({ path, method });
});
done();
});
```
Into this:
```
await fastify.register((instance, opts, done) => {
instance.addHook('onRoute', (routeOptions) => {
const { path, method } = routeOptions;
console.log({ path, method });
});
done();
});
```

## Non Breaking Changes

### Change of schema for multiple types
Expand Down

0 comments on commit 4eea272

Please sign in to comment.