(router, { rewriteUrl, logger })
| 800 | } |
| 801 | |
| 802 | function wrapRouting (router, { rewriteUrl, logger }) { |
| 803 | let isAsync |
| 804 | return function preRouting (req, res) { |
| 805 | class="cm">// only call isAsyncConstraint once |
| 806 | if (isAsync === undefined) isAsync = router.isAsyncConstraint() |
| 807 | if (rewriteUrl) { |
| 808 | req.originalUrl = req.url |
| 809 | const url = rewriteUrl.call(fastify, req) |
| 810 | if (typeof url === class="st">'string') { |
| 811 | req.url = url |
| 812 | } else { |
| 813 | const err = new FST_ERR_ROUTE_REWRITE_NOT_STR(req.url, typeof url) |
| 814 | req.destroy(err) |
| 815 | } |
| 816 | } |
| 817 | router.routing(req, res, buildAsyncConstraintCallback(isAsync, req, res)) |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | function setGenReqId (func) { |
| 822 | throwIfAlreadyStarted(class="st">'Cannot call "setGenReqId"!') |
no test coverage detected