MCPcopy
hub / github.com/fastify/fastify / wrapRouting

Function wrapRouting

fastify.js:802–819  ·  fastify.js::wrapRouting
(router, { rewriteUrl, logger })

Source from the content-addressed store, hash-verified

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"!')

Callers 1

fastifyFunction · 0.85

Calls 2

routingMethod · 0.80

Tested by

no test coverage detected