I have a rails app which provides real-time functionality through Faye. My clients are going to access the Faye server through example.com:9292/faye . Instead of using that address and revealing my machine's open ports, I am trying to add a rack middleware and by using 'rack-proxy' gem, proxy my example.com/faye requests to example.com:9292/faye . My Rails middleware code looks like this:
class FayeProxy < Rack::Proxy
def rewrite_env(env)
request = Rack::Request.new(env)
if request.path =~ %r{^/faye}
env["HTTP_HOST"] = "localhost:9292"
end
env
end
end
Also I added the middleware to config/application.rb by config.middleware.use "FayeProxy"
, but when I run my rails server I get the following error:
/gems/ruby-1.9.3-p194/gems/rack-proxy-0.5.0/lib/rack/proxy.rb:12:in 'initialize': undefined method `key?' for # (NoMethodError)
and even if I remove meta_request gem I will get
*/gems/ruby-1.9.3-p194/gems/rack-proxy-0.5.1/lib/rack/proxy.rb:12:in initialize': undefined method
key?' for # (NoMethodError) *
Any help is really appreciated if anybody has experienced this before or knows the solution.
Ps I'm using Rails 3.2.13, rack 1.4.5, rack-proxy 0.5.1.
似乎机架代理不应被视为中间件,而应通过此处所述的路径进行安装: http : //inductor.induktiv.at/blog/2010/05/23/mount-rack-apps-in- rails-3 / 。
I know this is old, but I was just having a similar issue, but I suspect that the folder you faye_proxy.rb
is in is not included in rails by default.
Adding an initializer maybe ./config/initializers/proxy.rb
which contains require "#{Rails.root}/lib/faye_proxy.rb"
Replace lib
with wherever you put the proxy.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.