Skip to content

Instantly share code, notes, and snippets.

@coffeejay
Created March 16, 2017 02:10
Show Gist options
  • Select an option

  • Save coffeejay/ae310bb24c00f5af126f8f5898f619ec to your computer and use it in GitHub Desktop.

Select an option

Save coffeejay/ae310bb24c00f5af126f8f5898f619ec to your computer and use it in GitHub Desktop.
use Rack::Static,
:urls => ["/images", "/js", "/css", "/fonts"],
:root => "public"
run lambda { |env|
request = Rack::Request.new(env)
file = request.env['REQUEST_URI'].match(/([^\/]+)(?=\.\w+$)/)
file = file ? file[0] : "index"
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open("public/#{file}.html", File::RDONLY)
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment