Last active
August 29, 2015 14:21
-
-
Save jay16/6f1a6665efa09fcedc20 to your computer and use it in GitHub Desktop.
pdf.js server with sinatra.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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