(router, { rewriteUrl, logger })
| 793 | } |
| 794 | |
| 795 | function wrapRouting (router, { rewriteUrl, logger }) { |
| 796 | let isAsync |
| 797 | return function preRouting (req, res) { |
| 798 | // only call isAsyncConstraint once |
| 799 | if (isAsync === undefined) isAsync = router.isAsyncConstraint() |
| 800 | if (rewriteUrl) { |
| 801 | req.originalUrl = req.url |
| 802 | const url = rewriteUrl.call(fastify, req) |
| 803 | if (typeof url === 'string') { |
| 804 | req.url = url |
| 805 | } else { |
| 806 | const err = new FST_ERR_ROUTE_REWRITE_NOT_STR(req.url, typeof url) |
| 807 | req.destroy(err) |
| 808 | } |
| 809 | } |
| 810 | router.routing(req, res, buildAsyncConstraintCallback(isAsync, req, res)) |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | function setGenReqId (func) { |
| 815 | throwIfAlreadyStarted('Cannot call "setGenReqId"!') |
no test coverage detected