Skip to content

Instantly share code, notes, and snippets.

@mlen
Created February 16, 2012 12:52
Show Gist options
  • Save mlen/1844634 to your computer and use it in GitHub Desktop.
Save mlen/1844634 to your computer and use it in GitHub Desktop.
Super stupid simple rack app to make livereload work
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