Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #\ -p 4000
- PublicDir = File.join(Dir.pwd, 'public')
- module Rack
- # Route directory URI's to index file.
- class DirectoryIndex
- def initialize(app, index='index.html')
- @app = app
- @index = [index].flatten
- end
- def call(env)
- if env['PATH_INFO'] =~ /\/$/
- if index = find_index(env)
- env['PATH_INFO'] += index
- end
- end
- @app.call(env)
- end
- def find_index(env)
- @index.find do |i|
- ::File.exist?(::File.join(PublicDir, env['PATH_INFO'], i))
- end
- end
- end
- end
- use Rack::DirectoryIndex # Use index.html as the directory index
- use Rack::ShowStatus # Nice looking 404s and other messages
- use Rack::ShowExceptions # Nice looking errors
- Rack::Mime::MIME_TYPES['.ttf'] = "font/truetype"
- Rack::Mime::MIME_TYPES['.otf'] = "font/opentype"
- run Rack::Directory.new(PublicDir)
Add Comment
Please, Sign In to add comment