Skip to content

Instantly share code, notes, and snippets.

@semmin
Created September 19, 2013 01:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semmin/6617951 to your computer and use it in GitHub Desktop.
Save semmin/6617951 to your computer and use it in GitHub Desktop.
require 'bundler/setup'
require 'sinatra/base'
require 'dalli'
require 'rack-cache'
require 'memcachier'
require 'newrelic_rpm'
# Initialize Memcachier on Rack::Cache
use Rack::Cache,
verbose: true,
metastore: Dalli::Client.new,
entitystore: "file:tmp/cache/rack/body"
# Serves static content with specific max-age
use Rack::Static,
:urls => ["/assets", "/images", "/javascripts", "/stylesheets", "/media" ],
:root => 'public',
:cache_control => 'public, max-age=2592000'
# Handles gzip compression
use Rack::Deflater
# The project root directory
$root = ::File.dirname(__FILE__)
# Make NewRelic play nice with Unicorn
NewRelic::Agent.after_fork(:force_reconnect => true) if defined? Unicorn
class SinatraStaticServer < Sinatra::Base
configure :production do
require 'newrelic_rpm'
end
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
source "http://rubygems.org"
group :development do
gem 'rake', '~> 0.9'
gem 'rack', '~> 1.4.1'
gem 'jekyll', '~> 0.12'
gem 'rdiscount', '~> 1.6.8'
gem 'pygments.rb', '~> 0.3.4'
gem 'RedCloth', '~> 4.2.9'
gem 'haml', '~> 3.1.7'
gem 'compass', '~> 0.12.2'
gem 'rubypants', '~> 0.2.0'
gem 'rb-fsevent', '~> 0.9'
gem 'stringex', '~> 1.4.0'
gem 'liquid', '~> 2.3.0'
end
gem 'sinatra', '~> 1.3.3'
gem 'dalli'
gem 'rack-cache'
gem 'memcachier'
gem 'unicorn'
gem 'newrelic_rpm'
GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.9)
chunky_png (1.2.5)
classifier (1.3.3)
fast-stemmer (>= 1.0.0)
compass (0.12.2)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
dalli (2.6.2)
directory_watcher (1.4.1)
fast-stemmer (1.0.1)
fssm (0.2.9)
haml (3.1.7)
jekyll (0.12.0)
classifier (~> 1.3)
directory_watcher (~> 1.1)
kramdown (~> 0.13.4)
liquid (~> 2.3)
maruku (~> 0.5)
pygments.rb (~> 0.3.2)
kgio (2.8.0)
kramdown (0.13.8)
liquid (2.3.0)
maruku (0.6.1)
syntax (>= 1.0.0)
memcachier (0.0.1)
newrelic_rpm (3.5.8.72)
posix-spawn (0.3.6)
pygments.rb (0.3.4)
posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.1.0)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-protection (1.3.2)
rack
raindrops (0.10.0)
rake (0.9.2.2)
rb-fsevent (0.9.1)
rdiscount (1.6.8)
rubypants (0.2.0)
sass (3.1.20)
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
stringex (1.4.0)
syntax (1.0.0)
tilt (1.3.3)
unicorn (4.6.2)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
yajl-ruby (1.1.0)
PLATFORMS
ruby
DEPENDENCIES
RedCloth (~> 4.2.9)
compass (~> 0.12.2)
dalli
haml (~> 3.1.7)
jekyll (~> 0.12)
liquid (~> 2.3.0)
memcachier
newrelic_rpm
pygments.rb (~> 0.3.4)
rack (~> 1.4.1)
rack-cache
rake (~> 0.9)
rb-fsevent (~> 0.9)
rdiscount (~> 1.6.8)
rubypants (~> 0.2.0)
sinatra (~> 1.3.3)
stringex (~> 1.4.0)
unicorn
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
# config/unicorn.rb
worker_processes 4
timeout 30
preload_app true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment