Skip to content

Instantly share code, notes, and snippets.

@ktheory
Last active December 14, 2015 12:38
Show Gist options
  • Save ktheory/5087320 to your computer and use it in GitHub Desktop.
Save ktheory/5087320 to your computer and use it in GitHub Desktop.
Rack::Attack heroku demo w/ Redis
require 'rubygems'
require 'bundler/setup'
require 'rack/attack'
require 'active_support'
require 'active_support/cache/redis_store'
redis = ENV['REDISTOGO_URL'] || 'localhost'
Rack::Attack.cache.store = ActiveSupport::Cache::RedisStore.new(redis)
Rack::Attack.throttle("path", :limit => 2, :period => 2) { |req| req.path }
use Rack::Attack
app = ->(env) { [200, {'Content-Type' => 'text/plain'}, ["Hello world\n"]] }
run app
source 'https://rubygems.org'
gem 'rack-attack', :ref => '1c01e6097ce18f486d887ebbeb9f0c4b434cd8f5', :git => 'https://github.com/kickstarter/rack-attack.git'
gem 'redis-activesupport'
GIT
remote: https://github.com/kickstarter/rack-attack.git
revision: 1c01e6097ce18f486d887ebbeb9f0c4b434cd8f5
ref: 1c01e6097ce18f486d887ebbeb9f0c4b434cd8f5
specs:
rack-attack (2.1.0)
rack
GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
i18n (0.6.4)
multi_json (1.6.1)
rack (1.5.2)
redis (3.0.3)
redis-activesupport (3.2.3)
activesupport (~> 3.2.3)
redis-store (~> 1.1.0)
redis-store (1.1.3)
redis (>= 2.2.0)
PLATFORMS
ruby
DEPENDENCIES
rack-attack!
redis-activesupport
web: bundle exec rackup config.ru -p $PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment