Heroku Config Secret Key Base Error

后端 未结 3 1304
迷失自我
迷失自我 2020-12-07 18:57

Just pushed my first app to Heroku using Git and straight away got an Interanl Server Error.

You must set config.secret_key_base in your app\'s config.

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 19:57

    In addition to setting the secret token as an ENV variable on Heroku, as outlined by Nick Ginanto, you also need the following to make this work.

    Remove the config/initializers/secret_token.rb from .gitignore

    Change the line in this file to:

    MyApp::Application.config.secret_token = ENV['SECRET_TOKEN']
    

    This will then pick up the secret token you have set with Heroku's config vars.

    In order for the token to be picked up in your local environment you will need to add it. There are a number of options here but the one closest to Heroku is to use the foreman gem along with a .env file in your project root. The .env will need to have the secret_token

    SECRET_TOKEN=NKUd7gisd7fueAISDfg....
    

    You can use the rake secret command to generate tokens. Make sure your .env file is added to .gitignore.

    With all this in place you will have different tokens for Heroku and local and your token will not be in your source control.

提交回复
热议问题