Last active
September 27, 2018 09:59
-
-
Save sj26/354d2e4923a0b3a4370f to your computer and use it in GitHub Desktop.
Use dotenv with unicorn (put in config/boot.rb, thanks @keithpitt)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "dotenv" | |
dotenv_root = File.expand_path("../../", __FILE__) | |
dotenv_env = ENV.fetch("RAILS_ENV", ENV.fetch("RACK_ENV", "development")) | |
dotenv_files = ["#{dotenv_root}/.env.#{dotenv_env}", "#{dotenv_root}/.env"] | |
if ENV.include? "DOTENV_LOADED" | |
ENV["DOTENV_LOADED"].split(":").each do |key| | |
ENV.delete(key) | |
end | |
end | |
dotenv_loaded = Dotenv.load(*dotenv_files) | |
ENV["DOTENV_LOADED"] = dotenv_loaded.keys.join(":") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment