Move HTTPS to server information
This commit is contained in:
parent
77dad2a400
commit
1d2126b9f7
2 changed files with 16 additions and 11 deletions
|
@ -13,10 +13,6 @@ module Middleman
|
||||||
attr_reader :app, :ssl_certificate, :ssl_private_key, :environment, :server_information
|
attr_reader :app, :ssl_certificate, :ssl_private_key, :environment, :server_information
|
||||||
delegate :logger, to: :app
|
delegate :logger, to: :app
|
||||||
|
|
||||||
def https?
|
|
||||||
@https
|
|
||||||
end
|
|
||||||
|
|
||||||
# Start an instance of Middleman::Application
|
# Start an instance of Middleman::Application
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def start(opts={})
|
def start(opts={})
|
||||||
|
@ -26,6 +22,7 @@ module Middleman
|
||||||
|
|
||||||
@options = opts
|
@options = opts
|
||||||
@server_information = ServerInformation.new
|
@server_information = ServerInformation.new
|
||||||
|
@server_information.https = (@options[:https] == true)
|
||||||
|
|
||||||
# New app evaluates the middleman configuration. Since this can be
|
# New app evaluates the middleman configuration. Since this can be
|
||||||
# invalid as well, we need to evaluate the configuration BEFORE
|
# invalid as well, we need to evaluate the configuration BEFORE
|
||||||
|
@ -42,9 +39,9 @@ module Middleman
|
||||||
|
|
||||||
logger.debug %(== Server information is provided by #{server_information.handler})
|
logger.debug %(== Server information is provided by #{server_information.handler})
|
||||||
logger.debug %(== The Middleman is running in "#{environment}" environment)
|
logger.debug %(== The Middleman is running in "#{environment}" environment)
|
||||||
logger.debug format('== The Middleman preview server is bind to %s', ServerUrl.new(hosts: server_information.listeners, port: server_information.port, https: https?).to_bind_addresses.join(', '))
|
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(', '))
|
||||||
logger.info format('== View your site at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: https?).to_urls.join(', '))
|
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(', '))
|
||||||
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(', '))
|
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
|
@initialized ||= false
|
||||||
return if @initialized
|
return if @initialized
|
||||||
|
@ -153,7 +150,6 @@ module Middleman
|
||||||
|
|
||||||
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
|
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]
|
@environment = @app.config[:environment]
|
||||||
|
|
||||||
@ssl_certificate = @app.config[:ssl_certificate]
|
@ssl_certificate = @app.config[:ssl_certificate]
|
||||||
|
@ -224,7 +220,7 @@ module Middleman
|
||||||
DoNotReverseLookup: true
|
DoNotReverseLookup: true
|
||||||
}
|
}
|
||||||
|
|
||||||
if https?
|
if server_information.https?
|
||||||
http_opts[:SSLEnable] = true
|
http_opts[:SSLEnable] = true
|
||||||
|
|
||||||
if ssl_certificate || ssl_private_key
|
if ssl_certificate || ssl_private_key
|
||||||
|
|
|
@ -20,6 +20,8 @@ module Middleman
|
||||||
|
|
||||||
public
|
public
|
||||||
|
|
||||||
|
attr_writer :https
|
||||||
|
|
||||||
def initialize(opts={})
|
def initialize(opts={})
|
||||||
@resolver = opts.fetch(:resolver, DnsResolver.new)
|
@resolver = opts.fetch(:resolver, DnsResolver.new)
|
||||||
@validator = opts.fetch(:validator, ServerInformationValidator.new)
|
@validator = opts.fetch(:validator, ServerInformationValidator.new)
|
||||||
|
@ -64,10 +66,12 @@ module Middleman
|
||||||
@bind_address = config[:bind_address]
|
@bind_address = config[:bind_address]
|
||||||
@port = config[:port]
|
@port = config[:port]
|
||||||
@server_name = config[:server_name]
|
@server_name = config[:server_name]
|
||||||
|
@https = config[:https]
|
||||||
|
|
||||||
config[:bind_address] = bind_address
|
config[:bind_address] = bind_address
|
||||||
config[:port] = port
|
config[:port] = port
|
||||||
config[:server_name] = server_name
|
config[:server_name] = server_name
|
||||||
|
config[:https] = https?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Make information of internal server class available to make debugging
|
# Make information of internal server class available to make debugging
|
||||||
|
@ -139,6 +143,11 @@ module Middleman
|
||||||
def listeners
|
def listeners
|
||||||
information.listeners
|
information.listeners
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Is https enabled?
|
||||||
|
def https?
|
||||||
|
@https == true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue