Skip to content

Commit

Permalink
Fix usage of deprecated Rack::File in Rack 3.0 (#896)
Browse files Browse the repository at this point in the history
Just a quick change to replace usage of Rack::File with Rack::Files, since this has been deprecated in Rack 3.0 and will be removed in Rack 3.1 (see https://github.com/rack/rack/blob/3-0-stable/lib/rack/file.rb).

Kept backward compatibility with older Rack versions by checking for the existence of Rack::Files before instantiating it, falling back to Rack::File.
  • Loading branch information
jamesds authored Oct 11, 2023
1 parent 79edf74 commit 7ab87c3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/apipie/static_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ class FileHandler
def initialize(root)
@root = root.chomp('/')
@compiled_root = /^#{Regexp.escape(root)}/
@file_server = ::Rack::File.new(@root)
@file_server = if defined?(::Rack::Files)
::Rack::Files.new(@root)
else
# Deprecated in Rack 3.0, kept
# for backward compatibility
::Rack::File.new(@root)
end
end

def match?(path)
Expand Down

0 comments on commit 7ab87c3

Please sign in to comment.