Created
February 16, 2012 12:52
-
-
Save mlen/1844634 to your computer and use it in GitHub Desktop.
Super stupid simple rack app to make livereload work
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
class App | |
def initialize(settings = {}) | |
@defaults = {:root_path => ".", :type => "text/plain", :file => "index.html"} | |
@defaults.merge(settings) | |
end | |
def call(env) | |
file = env['REQUEST_PATH'] == '/'? @defaults[:file] : env['REQUEST_PATH'] | |
[ | |
200, | |
{ | |
"Content-Type" => type(file) | |
}, | |
read(file) | |
] | |
end | |
def read(file) | |
File.readlines(File.join(File.expand_path(@defaults[:root_path]), file)) | |
end | |
def type(file) | |
content_types[File.extname(file)] || @defaults[:type] | |
end | |
def content_types | |
{ | |
".html" => "text/html", | |
".css" => "text/css", | |
".js" => "application/javascript", | |
".png" => "image/png", | |
".jpg" => "image/jpeg", | |
} | |
end | |
end | |
run App.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment