-
-
Save scalp42/f3eafe67116062ef8239 to your computer and use it in GitHub Desktop.
Can't use Rack middlewares
This file contains 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
# controllers/v1.rb | |
class ApiV1 < Scorched::Controller | |
get '/:key' do | |
'world' | |
end | |
end |
This file contains 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
$> shotgun test.ru | |
$> curl http://127.0.0.1:9393/v1/hello |
This file contains 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 'scorched' | |
require 'require_all' | |
require_rel 'controllers' | |
# in Gemfile | |
# gem 'improved-rack-throttle-w-expiry', git: 'git://github.com/Terrestre/improved-rack-throttle-w-expiry.git' | |
require 'rack/throttle' | |
class Test < Scorched::Controller | |
map pattern: '/v1', target: ApiV1 do | |
# Doesnt WORK when set for a certain controller | |
# need to wait 3 secs between requests, should store the count as throttle in Redis | |
use Rack::Throttle::Interval, :cache => Redis.new, :key_prefix => :throttle, :min => 3.0 | |
end | |
end | |
This file contains 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
#!/usr/bin/env ruby | |
require './test' | |
# Only WORKS if I set it here | |
# use Rack::Throttle::Interval, :cache => Redis.new, :key_prefix => :throttle, :min => 3.0 | |
run Test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment