From 9b8f2368fd53264c19574e8d6190f2a1b312c203 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Thu, 3 Nov 2011 11:00:35 +0100 Subject: [PATCH] Added static file serving from public/. --- stoptime.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/stoptime.rb b/stoptime.rb index fffabeb..2a4f4ce 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -13,6 +13,7 @@ require "active_support" require "camping" require "markaby" +require "mime/types" require "pathname" Markaby::Builder.set(:indent, 2) @@ -254,7 +255,20 @@ module StopTime::Controllers render :invoices end end - + + class StaticX + def get(path) + mime_type = MIME::Types.type_for(path).first + @headers['Content-Type'] = mime_type.nil? ? "text/plain" : mime_type.to_s + unless path.include? ".." + @headers['X-Sendfile'] = (BASE_DIR + path).to_s + else + @status = "403" + "Error 403: Invalid path: #{path}" + end + end + end + end # module StopTime::Controllers module StopTime::Views