我可以在Express中为路由添加描述吗?

时间:2014-07-08 09:54:58

标签: node.js express

我刚刚通过this blog post找到了一个很好的技巧。现在,在Express之后,我有这个简单的印刷品:

var routes = app._router.stack;
var Table = require('cli-table');
var table = new Table({ head: ["Name"] });
//var table = new Table({ head: ["Name", "Description"] });
for (var key in routes) {
    if (routes.hasOwnProperty(key)) {
        var val = routes[key];
        if(val.route) {
            var _o = [val.route.path];
            // but I'd like it to be:
            //var _o = [val.route.path, val.route.descrition]
            table.push(_o);
        }
    }
}
console.log(table.toString());
console.log('');

我想以编程方式添加说明。类似的东西:

app.get('/', function{
    this["description"] = "a nice description";
    // ...
}); 

有可能吗?

0 个答案:

没有答案