Skip to content

Instantly share code, notes, and snippets.

@lsiden
Created August 7, 2010 20:01
Show Gist options
  • Save lsiden/513127 to your computer and use it in GitHub Desktop.
Save lsiden/513127 to your computer and use it in GitHub Desktop.
get '/views/*' do
# Get file path. if refers to a directory, try index.html
path = params[:splat].first.split('/')
path = File.join('views', *path)
path = File.join(path, 'index.html') if File.directory?(path)
logger.debug(path)
# set long expiration headers
one_year = 360 * 24 * 60 * 60 # a little less than a year for proxy's-sake
time = Time.now + one_year
time = time.to_time if time.respond_to?(:to_time)
time = time.httpdate if time.respond_to?(:httpdate)
response['Expires'] = time
response['Cache-Control'] = "public, max-age=#{one_year}"
# send actual file
send_file(path)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment