Skip to content

Commit

Permalink
684-restore-localhost-url-with-initializers (#686)
Browse files Browse the repository at this point in the history
* Restore localhost url in development when using initializers

* Don't warn about missing config file if initializers config exists
  • Loading branch information
jaredcwhite authored Jan 2, 2023
1 parent f2417dd commit fdf92d6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bridgetown-core/lib/bridgetown-core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def from(user_config, starting_defaults = DEFAULTS)
end
end

def run_initializers!(context:)
def run_initializers!(context:) # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity
initializers_file = File.join(root_dir, "config", "initializers.rb")
return unless File.file?(initializers_file)

Expand All @@ -144,9 +144,11 @@ def run_initializers!(context:)
Bridgetown.logger.debug "Initializing:", "Running initializers with `#{context}' context in:"
Bridgetown.logger.debug "", initializers_file
self.init_params = {}
cached_url = url&.include?("//localhost") ? url : nil
dsl = ConfigurationDSL.new(scope: self, data: self)
dsl.instance_variable_set(:@context, context)
dsl.instance_exec(dsl, &init_init.block)
self.url = cached_url if cached_url # restore local development URL if need be

setup_load_paths! appending: true

Expand Down Expand Up @@ -308,7 +310,8 @@ def read_config_file(file)
next_config
rescue SystemCallError
if @default_config_file ||= nil
Bridgetown.logger.warn "Configuration file:", "none"
initializers_file = File.join(root_dir, "config", "initializers.rb")
Bridgetown.logger.warn "Configuration file:", "none" unless File.file?(initializers_file)
{}
else
Bridgetown.logger.error "Fatal:", "The configuration file '#{file}' could not be found."
Expand Down

0 comments on commit fdf92d6

Please sign in to comment.