refraction icon indicating copy to clipboard operation
refraction copied to clipboard

Initialisation options for middleware

Open xaethos opened this issue 11 years ago • 1 comments

Allows for passing a second parameter to the middleware which is made available in the request object. The use case for this is to allow for configuration depending on the environment, without hardcoding it into the rules.

refraction_rules.rb:

Refraction.configure do |req|
  server_host = req.options[:host]
  req.permanent! host: server_host if req.host != server_host
end

production.rb: config.middleware.insert_before(::Rack::Lock, ::Refraction, host: 'myapp.com')

staging.rb: config.middleware.insert_before(::Rack::Lock, ::Refraction, host: 'myapp-staging.herokuapp.com')

test.rb: config.middleware.insert_before(::Rack::Lock, ::Refraction, host: 'lvh.me')

Also: updates gems and uses Bundler.

xaethos avatar Jul 10 '13 01:07 xaethos

I'm open to alternative names for Refraction::Request#options. I thought of using config but that clashes with Refraction.configure.

xaethos avatar Jul 10 '13 01:07 xaethos