Skip to content

Instantly share code, notes, and snippets.

@aisuii
Created June 1, 2011 05:44
Show Gist options
  • Save aisuii/1001842 to your computer and use it in GitHub Desktop.
Save aisuii/1001842 to your computer and use it in GitHub Desktop.
static.ru
require 'rack'
HANDLER = Rack::Handler::Thin
PORT = 9292
PUBLIC_DIR = "public"
module Rack
class File
def _call(env)
@path_info = Rack::Utils.unescape(env["PATH_INFO"])
return forbidden if @path_info.include? ".."
@path = F.join(@root, @path_info)
@path = F.join(@path, 'index.html') if F.directory?(@path)
begin
if F.file?(@path) && F.readable?(@path)
serving
else
raise Errno::EPERM
end
rescue SystemCallError
not_found
end
end
end
end
HANDLER.run Rack::Static.new(nil, :urls => ["/"], :root => PUBLIC_DIR), :Port => PORT
@aisuii
Copy link
Author

aisuii commented Jun 1, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment