Merge branch 'sinatra_static_server' of https://github.com/scottwater/octopress into scottwater-sinatra_static_server
Conflicts: Gemfile Gemfile.lock
This commit is contained in:
commit
71ad7185bc
4
Gemfile
4
Gemfile
@ -1,5 +1,6 @@
|
|||||||
source "http://rubygems.org"
|
source "http://rubygems.org"
|
||||||
|
|
||||||
|
group :development do
|
||||||
gem 'rake'
|
gem 'rake'
|
||||||
gem 'rack'
|
gem 'rack'
|
||||||
gem 'jekyll'
|
gem 'jekyll'
|
||||||
@ -11,3 +12,6 @@ gem 'compass', '>= 0.11'
|
|||||||
gem 'rubypants'
|
gem 'rubypants'
|
||||||
gem 'rb-fsevent'
|
gem 'rb-fsevent'
|
||||||
gem 'stringex'
|
gem 'stringex'
|
||||||
|
end
|
||||||
|
|
||||||
|
gem 'sinatra', '1.2.6'
|
||||||
|
@ -39,9 +39,17 @@ GEM
|
|||||||
rubypython (0.5.1)
|
rubypython (0.5.1)
|
||||||
blankslate (>= 2.1.2.3)
|
blankslate (>= 2.1.2.3)
|
||||||
ffi (~> 1.0.7)
|
ffi (~> 1.0.7)
|
||||||
|
<<<<<<< HEAD
|
||||||
sass (3.1.7)
|
sass (3.1.7)
|
||||||
|
=======
|
||||||
|
sass (3.1.5)
|
||||||
|
sinatra (1.2.6)
|
||||||
|
rack (~> 1.1)
|
||||||
|
tilt (>= 1.2.2, < 2.0)
|
||||||
|
>>>>>>> 423e8ecbda0394d4c77e2ea659768a8f30c35018
|
||||||
stringex (1.3.0)
|
stringex (1.3.0)
|
||||||
syntax (1.0.0)
|
syntax (1.0.0)
|
||||||
|
tilt (1.3.2)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
@ -57,4 +65,5 @@ DEPENDENCIES
|
|||||||
rb-fsevent
|
rb-fsevent
|
||||||
rdiscount
|
rdiscount
|
||||||
rubypants
|
rubypants
|
||||||
|
sinatra (= 1.2.6)
|
||||||
stringex
|
stringex
|
||||||
|
40
config.ru
40
config.ru
@ -1,35 +1,25 @@
|
|||||||
require 'rubygems'
|
|
||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
require 'rack'
|
require 'sinatra/base'
|
||||||
|
|
||||||
# The project root directory
|
# The project root directory
|
||||||
$root = ::File.dirname(__FILE__)
|
$root = ::File.dirname(__FILE__)
|
||||||
|
|
||||||
# Common Rack Middleware
|
class SinatraStaticServer < Sinatra::Base
|
||||||
use Rack::ShowStatus # Nice looking 404s and other messages
|
|
||||||
use Rack::ShowExceptions # Nice looking errors
|
|
||||||
|
|
||||||
#
|
get(/.+/) do
|
||||||
# From Rack::DirectoryIndex:
|
send_sinatra_file(request.path) {404}
|
||||||
# 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
|
|
||||||
end
|
|
||||||
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
|
Loading…
Reference in New Issue
Block a user