当前我正试图在运行时删除一个 Node.js服务器应用程序的路由。Node.js在服务器运行时删除路由
for (k in self.app.routes.get) {
if (self.app.routes.get[k].path + "" === route + "") {
delete self.app.routes.get[k];
break;
}
}
调用此方法后,不再有self.app.routes对象中的路由。但之后,我尝试访问当前删除路线,我得到以下错误:由于express.js的文档
TypeError: Cannot call method 'match' of undefined at Router.matchRequest (/var/lib/root/runtime/repo/node_modules/express/lib/router/index.js:205:17)
这一定是这样做的正确方法。
The app.routes object houses all of the routes defined mapped by the associated HTTP verb. This object may be used for introspection capabilities, for example Express uses this internally not only for routing but to provide default OPTIONS behaviour unless app.options() is used. Your application or framework may also remove routes by simply by removing them from this object.
是否有任何机构知道如何在Node.js中的运行时正确删除路由?
非常感谢!
你能确认你的Express版本吗? – Brad 2013-02-22 15:30:20
对不起。我的版本是:“3.1.0” – 2013-02-22 15:32:49