can't access env['api.endpoint'] in grape middleware -


here use grape write api function. , want throttling api (api rate limit).

lib/grape/extensions/grape_extension.rb

module grape   module extension     module throttleextension       def throttle(options={})         route_setting :throttle, options         options       end       grape::api.extend self     end   end end 

lib/grape/middleware/throttle_middleware.rb

module grape   module middleware     class throttlemiddleware < grape::middleware::base       def before         binding.pry       end     end   end end 

lib/grape_throttle.rb

require 'grape' require 'grape/extensions/throttle_extension' module grape   module middleware     autoload :throttlemiddleware, 'grape/middleware/grape_middleware'   end end 

last, in config/application.rb

require file.expand_path('../../lib/grape_throttle', __file__) config.middleware.use grape::middleware::throttlemiddleware 

and, when run rails s,and call api, binding.pry has called.

[1] pry(#<grape::middleware::throttlemiddleware>)> env['api.endpoint'] => nil 

i want know how can access env['api.endpoint'] in grape middleware?

you can access env by::

endpoint = @env["api.endpoint"]

i have tried in non-rails application , worked. details of api endpoint in variable.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -