Skip to content

Instantly share code, notes, and snippets.

@suhanlee
Created October 17, 2016 08:37
Show Gist options
  • Save suhanlee/f2a80a00131517d959a470dd8be5a313 to your computer and use it in GitHub Desktop.
Save suhanlee/f2a80a00131517d959a470dd8be5a313 to your computer and use it in GitHub Desktop.
Sinatra local directory server
require 'sinatra'
$pwd = ENV['PWD']
configure do
set :server, :puma
set :root, File.dirname(__FILE__)
set :port, 7777
end
get '/' do
@files = Dir.entries($pwd)
erb :index
end
get '/*' do
files = params['splat'].join("")
if Dir.exists?(files)
@dir = "/" + files
@files = Dir.entries($pwd + '/' + files)
erb :index
else
send_file files
end
end
__END__
@@ index
<% @files.each do |file| %>
<a href="<%= @dir %>/<%=file %>"><%=file %></a><br>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment