【发布时间】:2016-03-01 20:15:40
【问题描述】:
我有一个带有 straitfort 路由处理的 expressjs 应用程序,如下所示:
app.route('/').get(function(req, res, next) {
// handling code;
});
app.route('/account').get(function(req, res, next) {
// handling code;
});
app.route('/profile').get(function(req, res, next) {
// handling code;
});
现在我将所有代码都放在路由处理程序中,但我想尝试将其委托给某些类,例如以下。
app.route('/').get(function(req, res, next) {
new IndexPageController().get(req, res, next);
});
app.route('/account').get(function(req, res, next) {
new AccountPageController().get(req, res, next);
});
app.route('/profile').get(function(req, res, next) {
new ProfilePageController().get(req, res, next);
});
那么你对上面的方法有什么看法,也许你知道更好的方法?
【问题讨论】:
标签: node.js express controller routes express-4