Guest User

Untitled

a guest
Jun 24th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #\ -p 4000
  2.  
  3. PublicDir = File.join(Dir.pwd, 'public')
  4.  
  5. module Rack
  6. # Route directory URI's to index file.
  7. class DirectoryIndex
  8. def initialize(app, index='index.html')
  9. @app = app
  10. @index = [index].flatten
  11. end
  12. def call(env)
  13. if env['PATH_INFO'] =~ /\/$/
  14. if index = find_index(env)
  15. env['PATH_INFO'] += index
  16. end
  17. end
  18. @app.call(env)
  19. end
  20. def find_index(env)
  21. @index.find do |i|
  22. ::File.exist?(::File.join(PublicDir, env['PATH_INFO'], i))
  23. end
  24. end
  25. end
  26. end
  27.  
  28. use Rack::DirectoryIndex # Use index.html as the directory index
  29. use Rack::ShowStatus # Nice looking 404s and other messages
  30. use Rack::ShowExceptions # Nice looking errors
  31.  
  32. Rack::Mime::MIME_TYPES['.ttf'] = "font/truetype"
  33. Rack::Mime::MIME_TYPES['.otf'] = "font/opentype"
  34.  
  35. run Rack::Directory.new(PublicDir)
Add Comment
Please, Sign In to add comment