scratch/config.ru

53 lines
1.6 KiB
Text
Raw Normal View History

2011-09-13 11:26:44 +00:00
# This file is needed if you want to host this website
# using ruby rack. In particular on heroku.
require 'rubygems'
require 'rack'
2010-08-24 10:10:36 +00:00
require 'rack/contrib'
require 'rack-rewrite'
2010-08-24 10:10:36 +00:00
require 'mime/types'
2010-09-10 14:46:29 +00:00
use Rack::Deflater
2010-08-24 10:10:36 +00:00
use Rack::ETag
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
2010-08-23 12:50:49 +00:00
end
2010-08-24 10:10:36 +00:00
2010-09-03 12:35:24 +00:00
use Rack::Rewrite do
r302 %r{/(Softwares.*)}, 'http://web.me.com/yann.esposito/$1'
r302 %r{/(Perso.*)}, 'http://web.me.com/yann.esposito/$1'
2011-04-20 14:46:03 +00:00
r302 %r{/YPassword(.*)}, '/Scratch/en/softwares/ypassword/iphoneweb'
2010-10-26 20:39:12 +00:00
r302 %r{/(Bastien.*)}, 'http://web.me.com/yann.esposito/$1'
2010-09-03 12:35:24 +00:00
end
2010-08-24 10:10:36 +00:00
use Rack::TryStatic,
:root => "output", # static files root dir
:urls => %w[/], # match all requests
:try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially
2011-04-20 14:46:03 +00:00
errorFile='output/Scratch/en/error/404-not_found/index.html'
2010-08-24 10:10:36 +00:00
run lambda { [404, {
"Last-Modified" => File.mtime(errorFile).httpdate,
"Content-Type" => "text/html",
"Content-Length" => File.size(errorFile).to_s
}, File.read(errorFile)] }