class StackMob::Middleware::Rewrite
Public Class Methods
new(app)
click to toggle source
# File lib/stackmob/middleware/rewrite.rb, line 18 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# 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