aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Watermasysk <scottwater@gmail.com>2011-08-21 21:06:21 -0400
committerScott Watermasysk <scottwater@gmail.com>2011-08-21 21:06:21 -0400
commit423e8ecbda0394d4c77e2ea659768a8f30c35018 (patch)
treee29f5971d54d67fdd6830515108312b5ba5c0abb
parent23f05c11588a94d0d557ba973ada0e818b49bbb0 (diff)
downloadmy_new_personal_website-423e8ecbda0394d4c77e2ea659768a8f30c35018.tar.xz
my_new_personal_website-423e8ecbda0394d4c77e2ea659768a8f30c35018.zip
Static Server based on Sinatra
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).
Diffstat (limited to '')
-rw-r--r--Gemfile26
-rw-r--r--Gemfile.lock5
-rw-r--r--config.ru40
3 files changed, 35 insertions, 36 deletions
diff --git a/Gemfile b/Gemfile
index ffb614f2..cb423fa7 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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' \ No newline at end of file
+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' \ No newline at end of file
diff --git a/Gemfile.lock b/Gemfile.lock
index 55634060..e64b2114 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -40,8 +40,12 @@ GEM
blankslate (>= 2.1.2.3)
ffi (~> 1.0.7)
sass (3.1.5)
+ sinatra (1.2.6)
+ rack (~> 1.1)
+ tilt (>= 1.2.2, < 2.0)
stringex (1.3.0)
syntax (1.0.0)
+ tilt (1.3.2)
PLATFORMS
ruby
@@ -57,4 +61,5 @@ DEPENDENCIES
rb-fsevent
rdiscount
rubypants
+ sinatra (= 1.2.6)
stringex
diff --git a/config.ru b/config.ru
index 060867f3..b1b746b1 100644
--- a/config.ru
+++ b/config.ru
@@ -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 \ No newline at end of file