MCPcopy Create free account
hub / github.com/fastify/fastify / wrapRouting

Function wrapRouting

fastify.js:795–812  ·  view source on GitHub ↗
(router, { rewriteUrl, logger })

Source from the content-addressed store, hash-verified

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

Callers 1

fastifyFunction · 0.85

Calls 2

routingMethod · 0.80

Tested by

no test coverage detected