Class: Junebug::Controllers::Static

Inherits:
R
  • Object
show all
Defined in:
lib/junebug/controllers.rb

Constant Summary collapse

MIME_TYPES =
{'.css' => 'text/css', '.js' => 'text/javascript', '.jpg' => 'image/jpeg'}
PATH =

PATH = __FILE__[/(.*)//, 1]

ENV['JUNEBUG_ROOT'] || File.expand_path('.')

Instance Method Summary collapse

Instance Method Details

#get(path) ⇒ Object



213
214
215
216
217
218
219
220
# File 'lib/junebug/controllers.rb', line 213

def get(path)
  @headers['Content-Type'] = MIME_TYPES[path[/\.\w+$/, 0]] || "text/plain"
  unless path.include? '..' # sample test to prevent directory traversal attacks
    @headers['X-Sendfile'] = "#{PATH}/public#{path}"
  else
    "404 - Invalid path"
  end
end