From 9741c68d34c0c7dc906ed2f967c9bbb4d35f1a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=BCnnewig?= Date: Thu, 7 May 2015 09:21:11 +0200 Subject: [PATCH] Explicit set the hostname --- middleman-core/lib/middleman-core/application.rb | 4 ++++ middleman-core/lib/middleman-core/cli/server.rb | 4 ++++ middleman-core/lib/middleman-core/preview_server.rb | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index cc6f6a3d..28496679 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -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' diff --git a/middleman-core/lib/middleman-core/cli/server.rb b/middleman-core/lib/middleman-core/cli/server.rb index 41af4172..bf222dd2 100644 --- a/middleman-core/lib/middleman-core/cli/server.rb +++ b/middleman-core/lib/middleman-core/cli/server.rb @@ -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'], diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index ce6678b7..897c3f0f 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -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 }