I have been using the following in config/environments/staging.rb
to keep my staging
environment private:
# HTTP Basic Authentication
if ENV['AUTH_BASIC_ON'] == 'true'
config.middleware.insert_before(ActionDispatch::Static, 'Rack::Auth::Basic', 'Staging') do |username, password|
[username, password] == [ENV.fetch('AUTH_BASIC_USERNAME'), ENV.fetch('AUTH_BASIC_PASSWORD')]
end
end
What is config.middleware.insert_before
's third argument ('Staging'
)? What implication does this particular parameter bear? If I want to run this code in production
(by copy/pasting it into config/environments/production.rb
), should I change this parameter to 'Production'
? What if I change it to 'Fubar'
?
I tried looking this up in the docs and source code, but it is unexplained. Also, I found it mentioned in a book, but the explanation is weak at best:
The args parameter is an optional hash of attributes to pass to the initializer method of your Rack filter.
It's simply the message sent to the browser by the
Rack::Auth::Basic
middleware; look at the screenshot below :)