static.rb 401 B

1234567891011121314151617181920
  1. require 'rack/file'
  2. module Shotgun
  3. # Serves static files out of the specified directory.
  4. class Static
  5. def initialize(app, public_dir='./public')
  6. @file = Rack::File.new(public_dir)
  7. @app = app
  8. end
  9. def call(env)
  10. status, headers, body = @file.call(env)
  11. if status > 400
  12. @app.call(env)
  13. else
  14. [status, headers, body]
  15. end
  16. end
  17. end
  18. end