From b0644b26c7f4b2550b81ce2d80981a48f2269647 Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Sat, 4 Feb 2023 07:24:14 +0100 Subject: [PATCH] allow to set some configuration options via ENV --- config/initializers/10_config.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/config/initializers/10_config.rb b/config/initializers/10_config.rb index 2e12b5f4..deba98c4 100644 --- a/config/initializers/10_config.rb +++ b/config/initializers/10_config.rb @@ -1,5 +1,23 @@ +# frozen_string_literal: true + # Auxiliary config -APP_CONFIG = YAML.load_file(Rails.root.join('config', 'justask.yml')).with_indifferent_access + +APP_CONFIG = {}.with_indifferent_access + +# load yml config if it's present +justask_yml_path = Rails.root.join("config/justask.yml") +APP_CONFIG.merge!(YAML.load_file(justask_yml_path)) if File.exist?(justask_yml_path) + +# load config from ENV where possible +env_config = { + # The site name, shown everywhere + site_name: ENV.fetch("SITE_NAME", nil), + + hostname: ENV.fetch("HOSTNAME", nil), +}.compact +APP_CONFIG.merge!(env_config) # Update rails config for mail -Rails.application.config.action_mailer.default_url_options = { host: APP_CONFIG['hostname'] } +Rails.application.config.action_mailer.default_url_options = { + host: APP_CONFIG["hostname"], +}