Class: Strobe::Middleware::Rewrite
- Inherits:
-
Object
- Object
- Strobe::Middleware::Rewrite
- Defined in:
- lib/strobe/middleware/rewrite.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Rewrite
constructor
A new instance of Rewrite.
Constructor Details
#initialize(app) ⇒ Rewrite
Returns a new instance of Rewrite.
3 4 5 |
# File 'lib/strobe/middleware/rewrite.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/strobe/middleware/rewrite.rb', line 7 def call(env) status, hdrs, body = @app.call(env) original_response = [status, hdrs, body] if status == 404 path_info = env['PATH_INFO'] env['PATH_INFO'] = "#{path_info}/index.html".gsub('//', '/') status, hdrs, body = @app.call(env) if status == 404 env['PATH_INFO'] = "/404.html" status, hdrs, body = @app.call(env) if status == 404 status, hdrs, body = original_response else status = 404 end end end [ status, hdrs, body ] end |