Explicit set the hostname

v3-stable
Dennis Günnewig 2015-05-07 09:21:11 +02:00
parent 588f42f1df
commit 9741c68d34
3 changed files with 11 additions and 1 deletions

View File

@ -71,6 +71,10 @@ module Middleman
# @return [Fixnum]
config.define_setting :port, 4567, 'The preview server port'
# Which server name should be used
# @return [NilClass, String]
config.define_setting :host, nil , 'The preview host name'
# Whether to serve the preview server over HTTPS.
# @return [Boolean]
config.define_setting :https, false, 'Serve the preview server over SSL/TLS'

View File

@ -14,6 +14,9 @@ module Middleman::Cli
method_option :port,
aliases: '-p',
desc: 'The port Middleman will listen on'
method_option :host,
aliases: '-h',
desc: 'The host name Middleman will use'
method_option :https,
type: :boolean,
desc: 'Serve the preview server over SSL/TLS'
@ -66,6 +69,7 @@ module Middleman::Cli
params = {
port: options['port'],
https: options['https'],
host: options['host'],
ssl_certificate: options['ssl_certificate'],
ssl_private_key: options['ssl_private_key'],
environment: options['environment'],

View File

@ -112,12 +112,13 @@ module Middleman
config[:environment] = opts[:environment].to_sym if opts[:environment]
config[:port] = opts[:port] if opts[:port]
config[:host] = opts[:host].presence || Socket.gethostname.tr(' ', '+')
config[:https] = opts[:https] unless opts[:https].nil?
config[:ssl_certificate] = opts[:ssl_certificate] if opts[:ssl_certificate]
config[:ssl_private_key] = opts[:ssl_private_key] if opts[:ssl_private_key]
end
@host = Socket.gethostname.tr(' ', '+')
@host = @app.config[:host]
@port = @app.config[:port]
@https = @app.config[:https]
@ -182,6 +183,7 @@ module Middleman
http_opts = {
Port: port,
AccessLog: [],
ServerName: host,
DoNotReverseLookup: true
}