refraction
refraction copied to clipboard
Initialisation options for middleware
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.
I'm open to alternative names for Refraction::Request#options
. I thought of using config
but that clashes with Refraction.configure
.