Express4のRouterで階層構造のあるルータを指定する
var express = require('express'),
app, router;
app = express();
router = express.Router();
router.get('/aaa', function(req, res, next) {
res.end('aaa\n');
});
router.get('/bbb', function(req, res, next) {
res.end('bbb\n');
});
app.use('/root', router);
app.listen(3000);
$ curl http://localhost:3000/
Cannot GET /
$ curl http://localhost:3000/root
Cannot GET /root
$ curl http://localhost:3000/root/aaa
aaa
$ curl http://localhost:3000/root/bbb
bbb
なるほど。