lib/rack/app/singleton_methods/mounting.rb in rack-app-2.1.0 vs lib/rack/app/singleton_methods/mounting.rb in rack-app-2.2.0

- old
+ new

@@ -22,6 +22,34 @@ router.merge_router!(api_class.router, merge_prop) return nil end + def mount_directory(directory_path, options={}) + + directory_full_path = Rack::App::Utils.expand_path(directory_path) + + namespace options[:to] do + + Dir.glob(File.join(directory_full_path, '**', '*')).each do |file_path| + + request_path = file_path.sub(/^#{Regexp.escape(directory_full_path)}/, '') + get(request_path){ serve_file(file_path) } + options(request_path){ '' } + + end + + end + nil + + end + + alias create_endpoints_for_files_in mount_directory + + def serve_files_from(file_path, options={}) + file_server = Rack::App::FileServer.new(Rack::App::Utils.expand_path(file_path)) + request_path = Rack::App::Utils.join(@namespaces, options[:to], '**', '*') + router.register_endpoint!('GET', request_path, @last_description, file_server) + @last_description = nil + end + end