From fda46ad4f7b5d79454fd083ee95f6b0edc38447b Mon Sep 17 00:00:00 2001 From: Amy Grace Date: Wed, 16 Feb 2022 10:05:52 -0700 Subject: [PATCH] Move SSL instance variables into new preview server subclass (#2536) When the preview server was refactored in e1b0de9, these SSL-related variables were left in the original `PreviewServer` -- where the new `PreviewServer::Webrick` didn't know about them -- causing HTTPS preview servers to suffer a fatal `NameError` ("undefined local variable or method 'ssl_certificate'") during `Webrick#setup_webrick`. This commit changes `Webrick.new` to accept an `ssl_information` hash containing the necessary instance variables from the `PreviewServer`. --- middleman-core/lib/middleman-core/preview_server.rb | 9 ++++++--- .../lib/middleman-core/preview_server/webrick.rb | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index c2ec9408..07469413 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -13,7 +13,7 @@ module Middleman class << self extend Forwardable - attr_reader :app, :web_server, :ssl_certificate, :ssl_private_key, :environment, :server_information + attr_reader :app, :web_server, :ssl_information, :environment, :server_information # Start an instance of Middleman::Application # @return [void] @@ -202,8 +202,10 @@ module Middleman @environment = possible_from_cli(:environment, app.config) - @ssl_certificate = possible_from_cli(:ssl_certificate, app.config) - @ssl_private_key = possible_from_cli(:ssl_private_key, app.config) + @ssl_information = { + ssl_certificate: possible_from_cli(:ssl_certificate, app.config), + ssl_private_key: possible_from_cli(:ssl_private_key, app.config) + } reload_queue = Queue.new @@ -241,6 +243,7 @@ module Middleman @web_server = Webrick.new( ::Middleman::Rack.new(app).to_app, server_information, + ssl_information, @options[:debug] || false ) end diff --git a/middleman-core/lib/middleman-core/preview_server/webrick.rb b/middleman-core/lib/middleman-core/preview_server/webrick.rb index 23a81623..566461a3 100644 --- a/middleman-core/lib/middleman-core/preview_server/webrick.rb +++ b/middleman-core/lib/middleman-core/preview_server/webrick.rb @@ -7,9 +7,12 @@ require 'webrick/https' module Middleman class PreviewServer class Webrick - attr_reader :webrick + attr_reader :webrick, :ssl_certificate, :ssl_private_key + + def initialize(rack_app, server_information, ssl_information, is_debug) + @ssl_certificate = ssl_information[:ssl_certificate] + @ssl_private_key = ssl_information[:ssl_private_key] - def initialize(rack_app, server_information, is_debug) @webrick = setup_webrick(server_information, is_debug) webrick.mount '/', ::Rack::Handler::WEBrick, rack_app end