diff --git a/docs/Reference/Routes.md b/docs/Reference/Routes.md index 018cc51301a..93567c1eb10 100644 --- a/docs/Reference/Routes.md +++ b/docs/Reference/Routes.md @@ -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) { @@ -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')({ diff --git a/fastify.js b/fastify.js index a4669d0ec74..47619473128 100644 --- a/fastify.js +++ b/fastify.js @@ -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) { @@ -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)) } } }