Created
June 1, 2011 05:44
-
-
Save aisuii/1001842 to your computer and use it in GitHub Desktop.
static.ru
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
すでにあった http://blog.udzura.jp/2011/04/08/naive-static-site-withrack/