Skip to content

Commit

Permalink
fix: don't use config URL directly for Puma binding in production
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed May 6, 2024
1 parent 603a9f4 commit c428f02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 8 additions & 9 deletions bridgetown-core/lib/bridgetown-core/commands/start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions bridgetown-website/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit c428f02

Please sign in to comment.