Last active
December 14, 2015 12:38
-
-
Save ktheory/5087320 to your computer and use it in GitHub Desktop.
Rack::Attack heroku demo w/ Redis
This file contains hidden or 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 '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 |
This file contains hidden or 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 'https://rubygems.org' | |
gem 'rack-attack', :ref => '1c01e6097ce18f486d887ebbeb9f0c4b434cd8f5', :git => 'https://github.com/kickstarter/rack-attack.git' | |
gem 'redis-activesupport' |
This file contains hidden or 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
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 |
This file contains hidden or 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
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