MiddlewareStackProxy
是 Rails 中间件堆栈的代理,允许您在应用程序中配置中间件。它基本上充当命令记录器,将每个命令保存到初始化后应用于默认中间件堆栈,因此您可以添加、交换或删除 Rails 中的任何中间件。
您可以使用 config.middleware.use
方法添加自己的中间件
config.middleware.use Magical::Unicorns
这将把 Magical::Unicorns
中间件放在堆栈的末尾。如果您希望在另一个中间件之前添加中间件,可以使用 insert_before
config.middleware.insert_before Rack::Head, Magical::Unicorns
还有 insert_after
,它将在另一个中间件之后插入中间件
config.middleware.insert_after Rack::Head, Magical::Unicorns
中间件也可以完全替换为其他中间件
config.middleware.swap ActionDispatch::Flash, Magical::Unicorns
中间件可以从一个位置移动到另一个位置
config.middleware.move_before ActionDispatch::Flash, Magical::Unicorns
这将把 Magical::Unicorns
中间件移动到 ActionDispatch::Flash
之前。您也可以将其移动到之后
config.middleware.move_after ActionDispatch::Flash, Magical::Unicorns
最后,它们也可以从堆栈中完全删除
config.middleware.delete ActionDispatch::Flash
- D
- I
- M
- N
- S
- U
属性
[R] | delete_operations | |
[R] | operations |
类公共方法
new(operations = [], delete_operations = []) 链接
来源:显示 | 在 GitHub 上
# File railties/lib/rails/configuration.rb, line 47 def initialize(operations = [], delete_operations = []) @operations = operations @delete_operations = delete_operations end
实例公共方法
delete(...) 链接
来源:显示 | 在 GitHub 上
# File railties/lib/rails/configuration.rb, line 70 def delete(...) @delete_operations << -> middleware { middleware.delete(...) } end
insert_after(...) 链接
来源:显示 | 在 GitHub 上
# File railties/lib/rails/configuration.rb, line 58 def insert_after(...) @operations << -> middleware { middleware.insert_after(...) } end
insert_before(...) 链接
来源:显示 | 在 GitHub 上
# File railties/lib/rails/configuration.rb, line 52 def insert_before(...) @operations << -> middleware { middleware.insert_before(...) } end
move_after(...) 链接
来源:显示 | 在 GitHub 上
# File railties/lib/rails/configuration.rb, line 80 def move_after(...) @delete_operations << -> middleware { middleware.move_after(...) } end
move_before(...) 链接
来源:显示 | 在 GitHub 上
# File railties/lib/rails/configuration.rb, line 74 def move_before(...) @delete_operations << -> middleware { middleware.move_before(...) } end
swap(...) 链接
来源:显示 | 在 GitHub 上
# File railties/lib/rails/configuration.rb, line 62 def swap(...) @operations << -> middleware { middleware.swap(...) } end
unshift(...) 链接
来源:显示 | 在 GitHub 上
# File railties/lib/rails/configuration.rb, line 84 def unshift(...) @operations << -> middleware { middleware.unshift(...) } end
use(...) 链接
来源:显示 | 在 GitHub 上查看
# File railties/lib/rails/configuration.rb, line 66 def use(...) @operations << -> middleware { middleware.use(...) } end