Commit d7b0b949 authored by Antonio Terceiro's avatar Antonio Terceiro

api: add skeleton

parent b57d56a6
require 'debci/api'
LISTING = <<EOF
<!DOCTYPE html>
<html>
<body>
<h1>Index of <%= request.path %></h1>
<div><a href="..">..</a></div>
<% Dir.chdir(@dir) do %>
<% Dir.glob('*').each do |f| %>
<% h = File.directory?(f) ? f + '/': f %>
<div><a href="<%= h %>"><%= f %></a></div>
<% end %>
<% end %>
</body>
</html>
EOF
class ServeStatic < Sinatra::Base
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, "<h1>404 Not Found</h1>")
end
end
end
end
app = Rack::Builder.new do
run ServeStatic
map '/api' do
run Debci::API
end
end
run app
require 'sinatra'
module Debci
class API < Sinatra::Base
end
end
require 'debci/api'
run Debci::API
......@@ -12,9 +12,7 @@ case $# in
;;
esac
document_root="$(dirname $0)/../public"
echo "I: Go to: http://localhost:$port/"
echo "I: Web UI at http://localhost:$port/"
echo "I: Hit Control+C to stop"
echo ""
cd "$document_root" && python3 -m http.server "$port"
rerun --background --dir lib -- rackup --include lib --port="$port"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment