Files
main.tsmain
What you'll learn
- Group routes in an express.Router() in their own file and mount it with app.use(path, router)
- Load what a route parameter names once with router.param, and scope middleware to one router
- Nest a router under a parameterised path with mergeParams, and read req.baseUrl, req.path and req.originalUrl
Press Run tests to start the app. Its log appears here.Graded endpoints
Mounted under /cats: its GET / answers GET /cats, with the router's own header
router.param loaded the cat into res.locals before the route ran
The param handler answered, and the route never ran
Inside a router, req.baseUrl is where it is mounted and req.path is the rest; req.originalUrl is the whole URL
A second router, a second header
The owners router's own :ownerId route
404, with the owners router's header
The nested router read :ownerId from its mount path, which only mergeParams allows
The same router, another owner
There is no owner 9 to list cats for