Removed throttling - #204
Andrew Kane
committed Aug 18, 2016
commit c452c9577f530d99ed5cb79d0447516ff07b3368
Showing 4
changed files with
15 additions
and 22 deletions
README.md
+12
-0
| @@ | @@ -530,6 +530,18 @@ Send a `POST` request as `Content-Type: application/json` to `/ahoy/events` with |
| Use an array to pass multiple events at once. | |
| + | ## Throttling |
| + | |
| + | To throttle requests to Ahoy endpoints, check out [Rack::Attack](https://github.com/kickstarter/rack-attack). Here’s a sample config: |
| + | |
| + | ```ruby |
| + | Rack::Attack.throttle("ahoy/ip", limit: 20, period: 1.minute) do |req| |
| + | if req.path.start_with?("/ahoy/") |
| + | req.ip |
| + | end |
| + | end |
| + | ``` |
| + | |
| ## Reference | |
| By default, Ahoy create endpoints at `/ahoy/visits` and `/ahoy/events`. To disable, use: | |
ahoy.rb b/lib/ahoy.rb
+3
-0
| @@ | @@ -72,12 +72,15 @@ module Ahoy |
| mattr_accessor :mount | |
| self.mount = true | |
| + | # no longer used |
| mattr_accessor :throttle | |
| self.throttle = true | |
| + | # no longer used |
| mattr_accessor :throttle_limit | |
| self.throttle_limit = 20 | |
| + | # no longer used |
| mattr_accessor :throttle_period | |
| self.throttle_period = 1.minute | |
ahoy/engine.rb b/lib/ahoy/engine.rb
+0
-5
| @@ | @@ -1,11 +1,6 @@ |
| module Ahoy | |
| class Engine < ::Rails::Engine | |
| initializer "ahoy.middleware", after: "sprockets.environment" do |app| | |
| - | if Ahoy.throttle |
| - | require "ahoy/throttle" |
| - | app.middleware.use Ahoy::Throttle |
| - | end |
| - | |
| next unless Ahoy.quiet | |
| # Parse PATH_INFO by assets prefix | |
ahoy/throttle.rb b/lib/ahoy/throttle.rb
+0
-17
| @@ | @@ -1,17 +0,0 @@ |
| - | require "rack/attack" |
| - | |
| - | module Ahoy |
| - | class Throttle < Rack::Attack |
| - | throttle("ahoy/ip", limit: Ahoy.throttle_limit, period: Ahoy.throttle_period) do |req| |
| - | if req.path.start_with?("/ahoy/") |
| - | req.ip |
| - | end |
| - | end |
| - | |
| - | def_delegators self, :whitelisted?, :blacklisted?, :throttled?, :tracked? |
| - | |
| - | def self.throttled_response |
| - | Rack::Attack.throttled_response |
| - | end |
| - | end |
| - | end |