Skip to content

Commit

Permalink
fix: per comment
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed Oct 6, 2022
1 parent 71c97ce commit 219de22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 5 additions & 4 deletions docs/Reference/Routes.md
Expand Up @@ -734,9 +734,10 @@ fastify.route({

#### Asynchronous Custom Constraints

You can provide your custom constraints and the `constraint` criteria can be fetch
from other source, for example `database`. Usage of asynchronous custom constraint
should place at the last resort since it impacts the router performance.
You can provide your custom constraints and the `constraint` criteria can be
fetched from other source, for example `database`. Usage of asynchronous custom
constraint should place at the last resort since it impacts the router
performance.

```js
function databaseOperation(field, done) {
Expand Down Expand Up @@ -767,7 +768,7 @@ const secret = {
> When using with asynchronous constraint. It is highly recommend never return error
> inside the callback. If the error is not preventable, it is recommended to provide
> a custom `frameworkErrors` handler to deal with it. Otherwise, you route selection
> may broken or expose sensitive information to hacker.
> may break or expose sensitive information to attackers.
>
> ```js
> const fastify = require('fastify')({
Expand Down
6 changes: 2 additions & 4 deletions fastify.js
Expand Up @@ -749,9 +749,7 @@ function fastify (options) {
return function preRouting (req, res) {
// only call isAsyncConstraint once
if (isAsync === undefined) isAsync = router.isAsyncConstraint()
if (!rewriteUrl) {
router.routing(req, res, buildAsyncConstraintCallback(isAsync, req, res))
} else {
if (rewriteUrl) {
const originalUrl = req.url
const url = rewriteUrl(req)
if (originalUrl !== url) {
Expand All @@ -762,8 +760,8 @@ function fastify (options) {
req.destroy(new Error(`Rewrite url for "${req.url}" needs to be of type "string" but received "${typeof url}"`))
}
}
router.routing(req, res, buildAsyncConstraintCallback(isAsync, req, res))
}
router.routing(req, res, buildAsyncConstraintCallback(isAsync, req, res))
}
}
}
Expand Down

0 comments on commit 219de22

Please sign in to comment.