config.ru
ef3ff431
 require 'bundler/setup'
423e8ecb
 require 'sinatra/base'
ef3ff431
 
 # The project root directory
 $root = ::File.dirname(__FILE__)
 
423e8ecb
 class SinatraStaticServer < Sinatra::Base  
ef3ff431
 
423e8ecb
   get(/.+/) do
     send_sinatra_file(request.path) {404}
ef3ff431
   end
 
423e8ecb
   not_found do
     send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"}
   end
ef3ff431
 
423e8ecb
   def send_sinatra_file(path, &missing_file_block)
     file_path = File.join(File.dirname(__FILE__), 'public',  path)
     file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i  
     File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
   end
 
 end
ef3ff431
 
423e8ecb
 run SinatraStaticServer