Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handy things for Heroku #37

Merged
merged 3 commits into from Feb 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Expand Up @@ -25,3 +25,7 @@ group :development, :test do
gem "pry-rails"
gem "rspec-rails", "~> 2.14"
end

group :production do
gem "rails_12factor"
end
6 changes: 6 additions & 0 deletions Gemfile.lock
Expand Up @@ -119,6 +119,11 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.3)
sprockets-rails (~> 2.0.0)
rails_12factor (0.0.2)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.2)
rails_stdout_logging (0.0.3)
railties (4.0.3)
actionpack (= 4.0.3)
activesupport (= 4.0.3)
Expand Down Expand Up @@ -198,5 +203,6 @@ DEPENDENCIES
pry-rails
puma (~> 2.7)
rails (~> 4.0.3)
rails_12factor
rspec-rails (~> 2.14)
twitter (~> 5.7)
8 changes: 7 additions & 1 deletion config/application.rb
@@ -1,4 +1,6 @@
require File.expand_path('../boot', __FILE__)
require File.expand_path("../boot", __FILE__)

require File.expand_path("../../lib/conditional_deflater", __FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
Expand Down Expand Up @@ -30,5 +32,9 @@ class Application < Rails::Application
config.i18n.enforce_available_locales = true

config.middleware.insert_after ActionDispatch::ParamsParser, ActionDispatch::XmlParamsParser
config.middleware.use ConditionalDeflater do |env|
# Don't gzip streaming endpoints
env["PATH_INFO"] !~ %r(^/room/\d+/live)
end
end
end
16 changes: 16 additions & 0 deletions lib/conditional_deflater.rb
@@ -0,0 +1,16 @@
require "rack/deflater"

class ConditionalDeflater
def initialize(app, &condition)
@app, @condition = app, condition
@deflater = Rack::Deflater.new(app)
end

def call(env)
if @condition && @condition.call(env)
@deflater.call(env)
else
@app.call(env)
end
end
end