config.ru
ef3ff431
 require 'bundler/setup'
423e8ecb
 require 'sinatra/base'
ef3ff431
 
 # The project root directory
 $root = ::File.dirname(__FILE__)
 
5b332f5c
 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)
5b332f5c
     file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i
423e8ecb
     File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
   end
 
 end
ef3ff431
 
5b332f5c
 run SinatraStaticServer