中间件如何删除? [英] how does a middleware get deleted?

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

问题描述

机架超时已包含在Gemfile中,但我们只希望将其用作生产中的中间件.因此,在初始化程序中,我们具有:

rack-timeout is included in the Gemfile, but we only want it as middleware on production. Thus in an initializer, we have:

config.middleware.delete Rack::Timeout

此行之前和之后的检查显示机架超时已从阵列中删除.无论如何,请求仍在超时,并且在gem中快速输入"put"就表明确实是罪魁祸首.

Inspecting before and after this line shows rack-timeout removed from the array. Regardless, requests are still timing out, and a quick 'puts' in the gem shows that it is indeed the culprit.

这是因为在调用delete之前已经构建了中间件堆栈吗?还是在每个请求中都读取了堆栈?如果是这样,可能是什么问题?

Is this because the middleware stack has already been built before delete is called? Or is the stack read in every request? If that's the case, what could be the issue?

推荐答案

为什么不仅有以下内容?

Why not just have something like the following?

group :production do
  gem "rack-timeout"
end

理论上,假设您正在谈论将某些内容放入config/initializers/,则初始化服务器中的中间件删除应解决该问题,然后重新启动服务器.

In theory, the middleware deletion in the initializer should take care of the problem after a server restart, assuming you're talking about putting something in config/initializers/.

进行了更多实验,并将其放入了config/initializers/rack-timeout.rb:

Did a little more experimentation and dropped this into config/initializers/rack-timeout.rb:

if Rails.env.production?
  Rack::Timeout.timeout = 0.5
else
  Rails.configuration.middleware.delete Rack::Timeout
end

这在脚手架控制器中:

sleep 1

重新启动开发服务器后,一切似乎都很酷(看不到超时:D).因此,也许只是一个错误的变量.

Everything seemed cool after I restarted the dev server (no timeouts in sight :D). So, maybe just a bad variable.

我仍然认为使用仅生产小组是更好的解决方案.

在OSX上使用Rails 3.2.2和ruby 1.9.2-p290运行.

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

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