Move HTTPS to server_information

This commit is contained in:
Dennis Günnewig 2015-11-07 18:50:55 +01:00
parent ec99a7b28f
commit a61b2e3b87
2 changed files with 16 additions and 11 deletions

View file

@ -15,10 +15,6 @@ module Middleman
attr_reader :app, :ssl_certificate, :ssl_private_key, :environment, :server_information
def https?
@https == true
end
# Start an instance of Middleman::Application
# @return [void]
def start(opts={})
@ -28,6 +24,7 @@ module Middleman
@options = opts
@server_information = ServerInformation.new
@server_information.https = (@options[:https] == true)
# New app evaluates the middleman configuration. Since this can be
# invalid as well, we need to evaluate the configuration BEFORE
@ -44,9 +41,9 @@ module Middleman
app.logger.debug %(== Server information is provided by #{server_information.handler})
app.logger.debug %(== The Middleman is running in "#{environment}" environment)
app.logger.debug format('== The Middleman preview server is bound to %s', ServerUrl.new(hosts: server_information.listeners, port: server_information.port, https: https?).to_bind_addresses.join(', '))
app.logger.info format('== View your site at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: https?).to_urls.join(', '))
app.logger.info format('== Inspect your site configuration at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: https?).to_config_urls.join(', '))
app.logger.debug format('== The Middleman preview server is bound to %s', ServerUrl.new(hosts: server_information.listeners, port: server_information.port, https: server_information.https?).to_bind_addresses.join(', '))
app.logger.info format('== View your site at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: server_information.https?).to_urls.join(', '))
app.logger.info format('== Inspect your site configuration at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: server_information.https?).to_config_urls.join(', '))
@initialized ||= false
return if @initialized
@ -170,7 +167,6 @@ module Middleman
app.logger.warn format('== The Middleman uses a different port "%s" then the configured one "%s" because some other server is listening on that port.', server_information.port, configured_port) unless app.config[:port] == configured_port
@https = app.config[:https]
@environment = app.config[:environment]
@ssl_certificate = app.config[:ssl_certificate]
@ -216,7 +212,7 @@ module Middleman
DoNotReverseLookup: true
}
if https?
if server_information.https?
http_opts[:SSLEnable] = true
if ssl_certificate || ssl_private_key

View file

@ -20,6 +20,8 @@ module Middleman
public
attr_writer :https
def initialize(opts={})
@resolver = opts.fetch(:resolver, DnsResolver.new)
@validator = opts.fetch(:validator, ServerInformationValidator.new)
@ -64,10 +66,12 @@ module Middleman
@bind_address = config[:bind_address]
@port = config[:port]
@server_name = config[:server_name]
@https = config[:https]
config[:bind_address] = bind_address
config[:port] = port
config[:server_name] = server_name
config[:port] = port
config[:server_name] = server_name
config[:https] = https?
end
# Make information of internal server class avaible to make debugging
@ -139,6 +143,11 @@ module Middleman
def listeners
information.listeners
end
# Is https enabled?
def https?
@https == true
end
end
end
end