// invoked for any requests passed to this router
router.use(function(req, res, next) {
// .. some logic here .. like any other middleware
next();
});
// will handle any request that ends in /events
// depends on where the router is "use()'d"
router.get('/events', function(req, res, next) {
// ..
});
You can then use a router for a particular root URL in this way separating your routes into files or even mini-apps.
// only requests to /calendar/* will be sent to our "router"
app.use('/calendar', router);
阅读上面代码有一些问题请教:
1.router.get('/events', function(req, res, next) {}); 是将函数映射到/events上,
而app.use('/calendar', router);是将中间件挂载到/calendar上。如果监听的3100端口,我们在浏览器中输入的http://127.0.0.1:3100/calendar,这是不会执行router.get('/events',function(){})中的函数的。上面说的You can then use a router for a particular root URL in this way separating your routes into files or even mini-apps.s这句话该怎么理解?particular root URL是什么?
天涯尽头无女友
相关分类