Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created September 5, 2014 22:53
Show Gist options
  • Save KamilLelonek/17762ebc5f83ba67a6ec to your computer and use it in GitHub Desktop.
Save KamilLelonek/17762ebc5f83ba67a6ec to your computer and use it in GitHub Desktop.
Serving static files from Rack
root = 'public'
use Rack::Static,
urls: Dir["#{root}/*"].map { |file| file.sub(root, '')},
root: root,
index: 'index.html',
header_rules: [[:all, { 'Cache-Control' => 'public, max-age=3600' }]]
run -> env {
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open("#{root}/index.html", File::RDONLY)
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment