Class: ImagesProxy
- Inherits:
-
Rack::Proxy
- Object
- Rack::Proxy
- ImagesProxy
- Defined in:
- lib/c80_shared/middleware/images_proxy.rb
Constant Summary collapse
- NEED_FAKE =
в урле должно содержаться это, чтобы запрос ушёл на боевой
/(system|ckeditor)/i- HOST =
боевой адрес + порт
'getboat.com:80'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ImagesProxy
constructor
A new instance of ImagesProxy.
- #rewrite_env(env) ⇒ Object
Constructor Details
#initialize(app) ⇒ ImagesProxy
Returns a new instance of ImagesProxy.
22 23 24 |
# File 'lib/c80_shared/middleware/images_proxy.rb', line 22 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/c80_shared/middleware/images_proxy.rb', line 26 def call(env) original_host = env['HTTP_HOST'] rewrite_env(env) if env['HTTP_HOST'] != original_host perform_request(env) else # just regular @app.call(env) end end |
#rewrite_env(env) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/c80_shared/middleware/images_proxy.rb', line 37 def rewrite_env(env) path = Rack::Request.new(env).path if path =~ NEED_FAKE && !File.exists?(path) env['HTTP_HOST'] = HOST env['SERVER_PORT'] = 80 else # do nothing end env end |