Last active
October 3, 2015 09:58
-
-
Save iphoting/2438514 to your computer and use it in GitHub Desktop.
Octopress config.ru
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
require 'bundler/setup' | |
require 'sinatra/base' | |
# The project root directory | |
$root = ::File.dirname(__FILE__) | |
class SinatraStaticServer < Sinatra::Base | |
get(/.+/) do | |
send_sinatra_file(request.path) {404} | |
end | |
not_found do | |
send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"} | |
end | |
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 |
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
require 'bundler/setup' | |
require 'sinatra/base' | |
# The project root directory | |
$root = ::File.dirname(__FILE__) | |
class SinatraStaticServer < Sinatra::Base | |
configure do | |
enable :static_cache_control | |
end | |
get(/.+/) do | |
send_sinatra_file(request.path) | |
end | |
not_found do | |
send_file(File.join(File.dirname(__FILE__), 'public', '404.html'), {:status => 404}) | |
end | |
def send_sinatra_file(path) | |
file_path = File.join(File.dirname(__FILE__), 'public', path) | |
file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i and !File.directory?(file_path) | |
File.exist?(file_path) ? send_file(file_path) : not_found | |
end | |
end | |
run SinatraStaticServer |
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
source "http://rubygems.org" | |
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' | |
gem 'liquid' | |
end | |
gem 'sinatra', "~> 1.4.0" | |
gem 'thin' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment