Class: StackMob::Middleware::Rewrite
- Inherits:
-
Object
- Object
- StackMob::Middleware::Rewrite
- Defined in:
- lib/stackmob/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.
18 19 20 |
# File 'lib/stackmob/middleware/rewrite.rb', line 18 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/stackmob/middleware/rewrite.rb', line 22 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 |