最近在做一个json api接口,需要匹配/api下的请求。
想要的实现是这样的:
app.path('/api', function(app){
// 匹配 /api/site_info
app.get('/site_info', someAction);
});
想要的实现是这样的:
app.path('/api', function(app){
// 匹配 /api/site_info
app.get('/site_info', someAction);
});

1 jasya May 27, 2014 req.params |
2 zoowii May 27, 2014 没用express 不过这种东西就算没有,自己封装一层context也可以了吧? 比如 var ctx = context(['GET', '/info', ...]); app.path('/api', ctx) |
3 kfll May 27, 2014 // http://expressjs.com/4x/api.html#router var router = express.Router() router.get('/site_info', someAction); router.get('/member_info', yetAnotherAction); app.get('/api', router); |
4 heroicYang May 27, 2014 @kfll 正解 不过这是 4.x 的 feature,哈哈~ |
5 luin May 27, 2014 via iPhone 可以看我写的文章: http://zihua.li/2014/05/good-practices-to-structure-an-express-app/ 具体来说可以使用 app.use('/app', subApp);,然后 subApp.get('/site_info' , func)。类似 namespace |
加上 npm install rainbow 效果更好 |