Static website configuration.
This commit is contained in:
parent
7b5cfbf3e0
commit
0da331c8c0
1 changed files with 37 additions and 5 deletions
42
config.ru
42
config.ru
|
@ -1,10 +1,42 @@
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'rack'
|
require 'rack'
|
||||||
|
require 'rack/contrib'
|
||||||
require 'rack-rewrite'
|
require 'rack-rewrite'
|
||||||
|
require 'mime/types'
|
||||||
|
|
||||||
use Rack::Rewrite do
|
use Rack::ETag
|
||||||
rewrite %r{(.*)/$},"$1/index.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
|
end
|
||||||
use Rack::Static, :urls => ["/"], :root => "output"
|
|
||||||
app = lambda { |env| [404, { 'Content-Type' => 'text/html' }, 'File Not Found'] }
|
use Rack::TryStatic,
|
||||||
run app
|
:root => "output", # static files root dir
|
||||||
|
:urls => %w[/], # match all requests
|
||||||
|
:try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially
|
||||||
|
|
||||||
|
errorFile='output/Scratch/en/error/404-not_found/index.html'
|
||||||
|
run lambda { [404, {
|
||||||
|
"Last-Modified" => File.mtime(errorFile).httpdate,
|
||||||
|
"Content-Type" => "text/html",
|
||||||
|
"Content-Length" => File.size(errorFile).to_s
|
||||||
|
}, File.read(errorFile)] }
|
||||||
|
|
Loading…
Reference in a new issue