[Rails]ベーシック認証をコントローラーに書かない方法

config.ru

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class CustomizedRackAuth < Rack::Auth::Basic
  def call(env)
    request = Rack::Request.new(env)

    if request.path == '/health_checks'
      @app.call(env)
    else
      super
    end
  end
end

use CustomizedRackAuth do |username, password|
  username == ENV['BASIC_AUTH_USERNAME'] && password == ENV['BASIC_AUTH_PASSWORD']
end
Built with Hugo
テーマ StackJimmy によって設計されています。