Last Updated: February 25, 2016
·
413
· 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