[refs #374] Add rate limit

This commit is contained in:
konstantin.grabar 2012-09-04 22:48:14 +04:00
parent ff8f9da14f
commit 58d9a972ef
3 changed files with 11 additions and 1 deletions

View File

@ -53,6 +53,8 @@ gem 'jquery-rails', '~> 2.0.2'
gem 'ruby-haml-js', '~> 0.0.3' gem 'ruby-haml-js', '~> 0.0.3'
gem 'rails-backbone', '~> 0.7.2' gem 'rails-backbone', '~> 0.7.2'
gem 'rack-throttle'
group :assets do group :assets do
gem 'sass-rails', '~> 3.2.5' gem 'sass-rails', '~> 3.2.5'
gem 'coffee-rails', '~> 3.2.2' gem 'coffee-rails', '~> 3.2.2'

View File

@ -223,6 +223,8 @@ GEM
rack rack
rack-test (0.6.1) rack-test (0.6.1)
rack (>= 1.0) rack (>= 1.0)
rack-throttle (0.3.0)
rack (>= 1.0.0)
rails (3.2.7) rails (3.2.7)
actionmailer (= 3.2.7) actionmailer (= 3.2.7)
actionpack (= 3.2.7) actionpack (= 3.2.7)
@ -394,6 +396,7 @@ DEPENDENCIES
paperclip (~> 3.1.4) paperclip (~> 3.1.4)
perform_later (~> 1.3.0) perform_later (~> 1.3.0)
pg (~> 0.14.0) pg (~> 0.14.0)
rack-throttle
rails (= 3.2.7) rails (= 3.2.7)
rails-backbone (~> 0.7.2) rails-backbone (~> 0.7.2)
rails3-generators rails3-generators

View File

@ -2,6 +2,7 @@
require File.expand_path('../boot', __FILE__) require File.expand_path('../boot', __FILE__)
require 'rails/all' require 'rails/all'
require 'rack/throttle'
# If you have a Gemfile, require the gems listed there, including any gems # If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production. # you've limited to :test, :development, or :production.
@ -14,6 +15,10 @@ end
module Rosa module Rosa
class Application < Rails::Application class Application < Rails::Application
# Rate limit
config.middleware.use Rack::Throttle::Interval, :cache => Redis.new, :key_prefix => :throttle, :min => 3.0
config.middleware.use Rack::Throttle::Hourly, :max => 100
config.middleware.use Rack::Throttle::Daily, :max => 5000
config.action_view.javascript_expansions[:defaults] = %w(jquery rails) config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
config.autoload_paths += %W(#{config.root}/lib) config.autoload_paths += %W(#{config.root}/lib)