Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

684-restore-localhost-url-with-initializers #686

Merged
merged 2 commits into from
Jan 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: How else other than running bin/bt dev can the value be set at this point? I'm unclear why we need to grab this cached_url because of my lack of understanding here.

Do we need to grab it because the port is overrideable? Because it can be set in other ways?

My hypothesis is that perhaps a bridgetown.config.yml has already been processed and we need to account for a value in there. Am I on the right track?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelherold it's overridden by the start command when in development environment before any other configuration has been loaded, even if there's a url key in the YAML config. But then when the initializers code is executed, setting url was overriding the localhost overwrite 😅. We want to undo that if necessary. There may be a more elegant way to refactor this in the near future…

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