Skip to content
Newer
Older
100644 25 lines (18 sloc) 632 Bytes
50fdd14 @FlaviuSim first commit after all the changes ;)
authored
1 require 'bundler/setup'
2 require 'sinatra/base'
3
4 # The project root directory
5 $root = ::File.dirname(__FILE__)
6
7 class SinatraStaticServer < Sinatra::Base
8
9 get(/.+/) do
10 send_sinatra_file(request.path) {404}
11 end
12
13 not_found do
14 send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"}
15 end
16
17 def send_sinatra_file(path, &missing_file_block)
18 file_path = File.join(File.dirname(__FILE__), 'public', path)
19 file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i
20 File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
21 end
22
23 end
24
25 run SinatraStaticServer
Something went wrong with that request. Please try again.