File: server.ru

package info (click to toggle)
ruby-rack-cache 1.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 648 kB
  • sloc: ruby: 3,581; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 881 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Rackup config that serves the contents of Rack::Cache's
# doc directory. The documentation is rebuilt on each request.

# Rewrites URLs like conventional web server configs.
class Rewriter < Struct.new(:app)
  def call(env)
    if env['PATH_INFO'] =~ /\/$/
      env['PATH_INFO'] += 'index.html'
    elsif env['PATH_INFO'] !~ /\.\w+$/
      env['PATH_INFO'] += '.html'
    end
    app.call(env)
  end
end

# Rebuilds documentation on each request.
class DocBuilder < Struct.new(:app)
  def call(env)
    if env['PATH_INFO'] !~ /\.(css|js|gif|jpg|png|ico)$/
      env['rack.errors'] << "*** rebuilding documentation (rake -s doc)\n"
      system "rake -s doc"
    end
    app.call(env)
  end
end

use Rack::CommonLogger
use DocBuilder
use Rewriter
use Rack::Static, :root => File.dirname(__FILE__), :urls => ["/"]

run(lambda{|env| [404,{},'<h1>Not Found</h1>']})

# vim: ft=ruby