Skip to content

Instantly share code, notes, and snippets.

@scalp42
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scalp42/f3eafe67116062ef8239 to your computer and use it in GitHub Desktop.
Save scalp42/f3eafe67116062ef8239 to your computer and use it in GitHub Desktop.
Can't use Rack middlewares
# controllers/v1.rb
class ApiV1 < Scorched::Controller
get '/:key' do
'world'
end
end
$> shotgun test.ru
$> curl http://127.0.0.1:9393/v1/hello
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
#!/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