diff options
author | Brandon Mathis <brandon@imathis.com> | 2011-09-08 10:31:36 -0500 |
---|---|---|
committer | Brandon Mathis <brandon@imathis.com> | 2011-09-08 10:31:36 -0500 |
commit | 71ad7185bc10b1fda8983fa73d195adb37654639 (patch) | |
tree | 3a0f3444842c2e102f50214dfee5edc6937ac0ca /config.ru | |
parent | a289c909092ff025e7444fa73b4039d112ecbce8 (diff) | |
parent | 423e8ecbda0394d4c77e2ea659768a8f30c35018 (diff) | |
download | my_new_personal_website-71ad7185bc10b1fda8983fa73d195adb37654639.tar.xz my_new_personal_website-71ad7185bc10b1fda8983fa73d195adb37654639.zip |
Merge branch 'sinatra_static_server' of https://github.com/scottwater/octopress into scottwater-sinatra_static_server
Conflicts:
Gemfile
Gemfile.lock
Diffstat (limited to '')
-rw-r--r-- | config.ru | 40 |
1 files changed, 15 insertions, 25 deletions
@@ -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 |