在 Node.js 中组织路由
我开始研究 Node.js.我也在使用 Express.我有一个问题 - 如何组织 Web 应用程序路由?所有示例都将所有这些 app.get/post/put()
处理程序放在 app.js 中,它工作得很好.这很好,但如果我有比简单的硬件博客更多的东西?是否可以做这样的事情:
I start to look at Node.js. Also I'm using Express.
And I have a question - how can I organize web application routes? All examples just put all this app.get/post/put()
handlers in app.js and it works just fine. This is good but if I have something more than a simple HW Blog? Is it possible to do something like this:
var app = express.createServer();
app.get( '/module-a/*', require('./module-a').urls );
app.get( '/module-b/*', require('./module-b').urls );
和
// file: module-a.js
urls.get('/:id', function(req, res){...}); // <- assuming this is handler for /module-a/1
换句话说 - 我想要类似 Django 的 URLConf 但在 Node.js 中的东西.
In other words - I'd like something like Django's URLConf but in Node.js.
在此处查看示例:
https://github.com/visionmedia/express/tree/master/examples
'mvc' 和 'route-separation' 可能会有所帮助.
'mvc' and 'route-separation' may be helpful.