require 'debci/api' LISTING = <

Index of <%= request.path %>

..
<% Dir.chdir(@dir) do %> <% Dir.glob('*').each do |f| %> <% h = File.directory?(f) ? f + '/': f %>
<%= f %>
<% end %> <% end %> EOF class ServeStatic < Sinatra::Base def static!(*args) # XXX static! is a private method, so this could break at some point if request.path =~ /log\.gz$/ headers['Content-Encoding'] = 'gzip' headers['Content-Type'] = 'text/plain; charset=utf-8' end super end get '/*' do if request.path !~ %r{/$} return redirect(request.path + '/') end index = File.join(settings.public_folder, request.path, 'index.html') if File.exist?(index) send_file(index, type: 'text/html') else @dir = File.dirname(index) if File.directory?(@dir) erb LISTING else halt(404, "

404 Not Found

") end end end end app = Rack::Builder.new do run ServeStatic map '/api' do run Debci::API end end run app