Skip to content

Instantly share code, notes, and snippets.

@jay16
Last active August 29, 2015 14:21
Show Gist options
  • Save jay16/6f1a6665efa09fcedc20 to your computer and use it in GitHub Desktop.
Save jay16/6f1a6665efa09fcedc20 to your computer and use it in GitHub Desktop.
pdf.js server with sinatra.
#encoding: utf-8
=begin
pdf.js server with sinatra.
put all your pdfjs_generic folder into together-path/ folder
then `cd together-path/ && ruby server.rb`
=end
require "sinatra"
get "/" do
builds = Dir.glob("build/generic*") + Dir.glob("generic*")
<<-HTML
<ul>
#{ builds.map { |path|
%Q{<li>
<a href="#{path}/web/viewer.html" target="_blank"> #{path} </a>
</li>}
}.join
}
</ul>
HTML
end
get "/*" do
filepath = params[:captures][0]
mime_type = case File.extname(filepath).downcase
when ".js" then "application/javascript"
when ".css" then "text/css"
when ".html" then "text/html"
when ".pdf" then "application/pdf"
else "text/plain"
end
content_type mime_type
IO.read filepath
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment