-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using Sinatra provides better handling of mime types and supports 304's/etc. Also updated the Gemfile to exclude most gem outside of developemnt (default).
- Loading branch information
1 parent
23f05c1
commit 423e8ec
Showing
3 changed files
with
35 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
source "http://rubygems.org" | ||
|
||
gem 'rake' | ||
gem 'rack' | ||
gem 'jekyll' | ||
gem 'rdiscount' | ||
gem 'pygments.rb' | ||
gem 'RedCloth' | ||
gem 'haml', '>= 3.1' | ||
gem 'compass', '>= 0.11' | ||
gem 'rubypants' | ||
gem 'rb-fsevent' | ||
gem 'stringex' | ||
group :development do | ||
gem 'rake' | ||
gem 'rack' | ||
gem 'jekyll' | ||
gem 'rdiscount' | ||
gem 'pygments.rb' | ||
gem 'RedCloth' | ||
gem 'haml', '>= 3.1' | ||
gem 'compass', '>= 0.11' | ||
gem 'rubypants' | ||
gem 'rb-fsevent' | ||
gem 'stringex' | ||
end | ||
|
||
gem 'sinatra', '1.2.6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,25 @@ | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
require 'rack' | ||
require 'sinatra/base' | ||
|
||
# The project root directory | ||
$root = ::File.dirname(__FILE__) | ||
|
||
# Common Rack Middleware | ||
use Rack::ShowStatus # Nice looking 404s and other messages | ||
use Rack::ShowExceptions # Nice looking errors | ||
class SinatraStaticServer < Sinatra::Base | ||
|
||
# | ||
# From Rack::DirectoryIndex: | ||
# https://github.com/craigmarksmith/rack-directory-index/ | ||
# | ||
module Rack | ||
class DirectoryIndex | ||
def initialize(app) | ||
@app = app | ||
end | ||
def call(env) | ||
index_path = ::File.join($root, 'public', Rack::Request.new(env).path.split('/'), 'index.html') | ||
if ::File.exists?(index_path) | ||
return [200, {"Content-Type" => "text/html"}, [::File.read(index_path)]] | ||
else | ||
@app.call(env) | ||
end | ||
end | ||
get(/.+/) do | ||
send_sinatra_file(request.path) {404} | ||
end | ||
end | ||
|
||
use Rack::DirectoryIndex | ||
not_found do | ||
send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"} | ||
end | ||
|
||
run Rack::Directory.new($root + '/public') | ||
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 | ||
|
||
run SinatraStaticServer |