node.js - app router in Express -
there difference between
app.use(function(req,res,next){ });
and
router.use('/some_route', function(req,res,next){ });
...the difference being app.use
runs every request , router.use
runs matching routes.
my question router must lie underneath app. surely app has default router internal it. there way access router...app.router? thought deprecated?
secondly, looking way access current router being used.
for example,
app.use(function(req,res,next){ var currentrouter = req.app._router // (?) });
or
router.use(function(req,res,next){ var currentrouter = req._router //(?) });
where req._router equal same router router.use call of course.
in latest express code, default app router in app._router
.
it created lazily means it's not created until route defined (with app.use()
or app.get()
or that).
it not appear meant public property , subject change. can, of course, define own router root path , use own router , not have access or use non-public property.
you correct app.router
deprecated. trying access purposely throws exception in express code.
Comments
Post a Comment