diff --git a/config.ru b/config.ru index 76223cb..a986bcf 100644 --- a/config.ru +++ b/config.ru @@ -24,6 +24,30 @@ $rootdir="site" $errorFile='site/404.html' $mailFile='site/mail_sent.html' + +module ::Rack + class TryStatic < Static + def initialize(app, options) + super + @try = ([''] + Array(options.delete(:try)) + ['']) + end + + def call(env) + @next = 0 + while @next < @try.size && 404 == (resp = super(try_next(env)))[0] + @next += 1 + end + 404 == resp[0] ? @app.call : resp + end + + private + def try_next(env) + env.merge('PATH_INFO' => env['PATH_INFO'] + @try[@next]) + end + + end +end + class MyMain < Rack::TryStatic def call(env) request = Rack::Request.new(env) @@ -48,7 +72,7 @@ class MyMain < Rack::TryStatic "Last-Modified" => File.mtime($mailFile).httpdate, "Content-Type" => "text/html", "Content-Length" => File.size($mailFile).to_s - }, File.read($mailFile)] + }, [File.read($mailFile)]] else super end