0
很多时候,我们希望在node.js中拆分路由器快速应用,我们做这样的时候...拆分路由器在快递子域
var express = require('express')
var router = express.Router()
// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
console.log('Time: ', Date.now())
next()
})
// define the home page route
router.get('/', function (req, res) {
res.send('Birds home page')
})
// define the about route
router.get('/about', function (req, res) {
res.send('About birds')
})
module.exports = router
然后,在应用程序加载路由器模块:
var birds = require('./birds')
// ...
app.use('/birds', birds)
但是,在快速子域,有没有什么办法可以像上面那样在子域中为鸟类分割路由器呢?
var router = express.Router();
//api specific routes
router.get('/', function(req, res) {
res.send('Welcome to our API!');
});
router.get('/birds', function(req, res) {
res.json([
{ name: "Brian" }
]);
});
然后,加载应用路由器模块:(这不是让我分裂更加路由器???)
app.use(subdomain('api', router));