Skip to content

Instantly share code, notes, and snippets.

@tjogin
Created June 9, 2011 06:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjogin/1016148 to your computer and use it in GitHub Desktop.
Save tjogin/1016148 to your computer and use it in GitHub Desktop.
Simple rack server
class Server
@@mime_types = { :txt => 'text/plain', :js => 'application/x-javascript', :css => 'text/css' }
def call(env)
file = file_name env["REQUEST_PATH"]
if File.exists? file
[200, { 'Content-Type' => mime_type_for_file(file) }, [ File.read(file) ] ]
else
[404, { 'Content-Type' => 'text/html' }, []]
end
end
def file_name(path)
if path[-1..-1] == "/"
path += "index.html"
end
return path[1..-1]
end
def mime_type_for_file(file)
@@mime_types[file.split(".").last.to_sym] || 'text/html'
end
end
run Server.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment