LoginSignup
42
36

More than 5 years have passed since last update.

Heroku上のRailsアプリにBasic認証をかける

Last updated at Posted at 2015-04-27

(主にHerokuの環境変数の入れ方を)すぐ忘れて毎度のようにググってる気がするので、メモしておく。

application_controller.rbを編集

http_basic_authenticate_with :name => ENV['BASIC_AUTH_USERNAME'], :password => ENV['BASIC_AUTH_PASSWORD'] if Rails.env == "production"

をコントローラーの上部にでも設定する。

Herokuで環境変数をセットする

$ heroku config:add BASIC_AUTH_USERNAME="admin" BASIC_AUTH_PASSWORD="password"

これだけでおっけー。

42
36
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
42
36