从Express堆栈中删除中间件的正确方法? [英] Proper way to remove middleware from the Express stack?

查看:177
本文介绍了从Express堆栈中删除中间件的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有规范的方法来从堆栈中删除添加 app.use 的中间件?似乎应该可以直接修改 app.stack 数组,但我想知道是否有一个文件化的方法我应该先考虑。

Is there a canonical way to remove middleware added with app.use from the stack? It seems that it should be possible to just modify the app.stack array directly, but I am wondering if there is a documented method I should be considering first.

推荐答案

使用实际来自Connect(not Express)和所有它真正做的是将中间件功能推送到应用程序的堆栈

use actually comes from Connect (not Express), and all it really does is push the middleware function onto the app's stack.

所以你应该把这个函数很好地拼接出来。

So you should be just fine splicing the function out of the array.

但是,请记住,在应用程序中没有文档.stack 也没有删除中间件的功能。您遇到Connect的未来版本的风险,使更改与您的代码不兼容。

However, keep in mind there is no documentation around app.stack nor is there a function to remove middleware. You run the risk of a future version of Connect making changes incompatible with your code.

这篇关于从Express堆栈中删除中间件的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆