Last Updated: February 25, 2016
·
746
· centipedefarmer

wrap a sinatra app around a static website

For those times when you have a static web site but then it turns out you need to add a contact form or some such. Just sticking the whole site in public/ gets you most of the way there -- but that doesn't work for the default index.html page for paths like "/" or "/foo". So to catch those, you could use this as the very last route/action in your app, as a default/catch-all.

get '/*' do
  path = params[:splat].first
  path = File.join('public', path, 'index.html')
  send_file path
end

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

The website is part of the attack surface, not only the API behind it. Every script, iframe, and tag on a public page is code that did not go through the same review as the backend.

Security insights from Cside