server.ru 881 B

12345678910111213141516171819202122232425262728293031323334
  1. # Rackup config that serves the contents of Rack::Cache's
  2. # doc directory. The documentation is rebuilt on each request.
  3. # Rewrites URLs like conventional web server configs.
  4. class Rewriter < Struct.new(:app)
  5. def call(env)
  6. if env['PATH_INFO'] =~ /\/$/
  7. env['PATH_INFO'] += 'index.html'
  8. elsif env['PATH_INFO'] !~ /\.\w+$/
  9. env['PATH_INFO'] += '.html'
  10. end
  11. app.call(env)
  12. end
  13. end
  14. # Rebuilds documentation on each request.
  15. class DocBuilder < Struct.new(:app)
  16. def call(env)
  17. if env['PATH_INFO'] !~ /\.(css|js|gif|jpg|png|ico)$/
  18. env['rack.errors'] << "*** rebuilding documentation (rake -s doc)\n"
  19. system "rake -s doc"
  20. end
  21. app.call(env)
  22. end
  23. end
  24. use Rack::CommonLogger
  25. use DocBuilder
  26. use Rewriter
  27. use Rack::Static, :root => File.dirname(__FILE__), :urls => ["/"]
  28. run(lambda{|env| [404,{},'<h1>Not Found</h1>']})
  29. # vim: ft=ruby