From c428f0223d13ba14c8b1b50c113293abeba187fe Mon Sep 17 00:00:00 2001 From: Jared White Date: Mon, 6 May 2024 14:36:29 -0700 Subject: [PATCH] fix: don't use config URL directly for Puma binding in production --- .../lib/bridgetown-core/commands/start.rb | 17 ++++++++--------- bridgetown-website/Gemfile.lock | 5 +++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bridgetown-core/lib/bridgetown-core/commands/start.rb b/bridgetown-core/lib/bridgetown-core/commands/start.rb index cb7d70719..dca2a7590 100644 --- a/bridgetown-core/lib/bridgetown-core/commands/start.rb +++ b/bridgetown-core/lib/bridgetown-core/commands/start.rb @@ -61,7 +61,7 @@ def self.banner end summary "Start the web server, frontend bundler, and Bridgetown watcher" - def start # rubocop:todo Metrics/PerceivedComplexity + def start Bridgetown.logger.writer.enable_prefix Bridgetown::Commands::Build.print_startup_message sleep 0.25 @@ -71,17 +71,16 @@ def start # rubocop:todo Metrics/PerceivedComplexity # Load Bridgetown configuration into thread memory bt_options = configuration_with_overrides(options) + port = ENV.fetch("BRIDGETOWN_PORT", bt_options.port) + # TODO: support Puma serving HTTPS directly? + bt_bound_url = "http://#{bt_options.bind}:#{port}" # Set a local site URL in the config if one is not available - if Bridgetown.env.development? && !options["url"] - port = ENV["BRIDGETOWN_PORT"] || bt_options.port - bt_options.url = "http://#{bt_options.bind}:#{port}" - end + bt_options.url = bt_bound_url if Bridgetown.env.development? && !options["url"] - server_uri = URI(bt_options.url) Bridgetown::Server.new({ - Host: server_uri.host, - Port: server_uri.port, + Host: bt_options.bind, + Port: port, config: "config.ru", }).tap do |server| if server.serveable? @@ -106,7 +105,7 @@ def start # rubocop:todo Metrics/PerceivedComplexity } Bridgetown.logger.info "" - Bridgetown.logger.info "Booting #{server.name} at:", server_uri.to_s.magenta + Bridgetown.logger.info "Booting #{server.name} at:", bt_bound_url.to_s.magenta Bridgetown.logger.info "" server.start(after_stop_callback) diff --git a/bridgetown-website/Gemfile.lock b/bridgetown-website/Gemfile.lock index 94e21fda7..b67121e45 100644 --- a/bridgetown-website/Gemfile.lock +++ b/bridgetown-website/Gemfile.lock @@ -24,6 +24,7 @@ PATH liquid (>= 5.0, < 5.5) listen (~> 3.0) rack (>= 3.0) + rackup (~> 2.0) rake (>= 13.0) roda (~> 3.46) rouge (>= 3.0, < 5.0) @@ -111,6 +112,9 @@ GEM nio4r (~> 2.0) racc (1.7.1) rack (3.0.9.1) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) rake (13.0.6) rb-fsevent (0.11.2) rb-inotify (0.10.1) @@ -136,6 +140,7 @@ GEM tilt (2.2.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + webrick (1.8.1) zeitwerk (2.6.11) PLATFORMS