Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 25 lines (18 sloc) 0.632 kb
ef3ff431 » imathis
2011-06-24 1. Added html5 video with flash fallback.
1 require 'bundler/setup'
423e8ecb » scottwater
2011-08-21 Static Server based on Sinatra
2 require 'sinatra/base'
ef3ff431 » imathis
2011-06-24 1. Added html5 video with flash fallback.
3
4 # The project root directory
5 $root = ::File.dirname(__FILE__)
6
423e8ecb » scottwater
2011-08-21 Static Server based on Sinatra
7 class SinatraStaticServer < Sinatra::Base
ef3ff431 » imathis
2011-06-24 1. Added html5 video with flash fallback.
8
423e8ecb » scottwater
2011-08-21 Static Server based on Sinatra
9 get(/.+/) do
10 send_sinatra_file(request.path) {404}
ef3ff431 » imathis
2011-06-24 1. Added html5 video with flash fallback.
11 end
12
423e8ecb » scottwater
2011-08-21 Static Server based on Sinatra
13 not_found do
14 send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"}
15 end
ef3ff431 » imathis
2011-06-24 1. Added html5 video with flash fallback.
16
423e8ecb » scottwater
2011-08-21 Static Server based on Sinatra
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
ef3ff431 » imathis
2011-06-24 1. Added html5 video with flash fallback.
24
423e8ecb » scottwater
2011-08-21 Static Server based on Sinatra
25 run SinatraStaticServer
Something went wrong with that request. Please try again.