refactor to use `server_address`
This commit is contained in:
parent
01c33907a3
commit
a945a65818
|
@ -104,7 +104,12 @@ module Jekyll
|
||||||
def start_up_webrick(opts, destination)
|
def start_up_webrick(opts, destination)
|
||||||
server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
|
server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
|
||||||
server.mount(opts["baseurl"], Servlet, destination, file_handler_opts)
|
server.mount(opts["baseurl"], Servlet, destination, file_handler_opts)
|
||||||
Jekyll.logger.info "Server address:", server_address(server, opts)
|
Jekyll.logger.info "Server address:", server_address(
|
||||||
|
server.config[:SSLEnable],
|
||||||
|
server.config[:BindAddress],
|
||||||
|
server.config[:Port],
|
||||||
|
opts["baseurl"]
|
||||||
|
)
|
||||||
launch_browser server, opts if opts["open_url"]
|
launch_browser server, opts if opts["open_url"]
|
||||||
boot_or_detach server, opts
|
boot_or_detach server, opts
|
||||||
end
|
end
|
||||||
|
@ -124,23 +129,25 @@ module Jekyll
|
||||||
#
|
#
|
||||||
|
|
||||||
private
|
private
|
||||||
def server_address(server, opts)
|
def server_address(prefix, address, port, baseurl = nil)
|
||||||
format("%{prefix}://%{address}:%{port}%{baseurl}", {
|
format("%{prefix}://%{address}:%{port}%{baseurl}", {
|
||||||
:prefix => server.config[:SSLEnable] ? "https" : "http",
|
:prefix => prefix ? "https" : "http",
|
||||||
:baseurl => opts["baseurl"] ? "#{opts["baseurl"]}/" : "",
|
:address => address,
|
||||||
:address => server.config[:BindAddress],
|
:port => port,
|
||||||
:port => server.config[:Port]
|
:baseurl => baseurl ? "#{baseurl}/" : ""
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
|
private
|
||||||
def default_url(opts)
|
def default_url(opts)
|
||||||
config = configuration_from_options(opts)
|
config = configuration_from_options(opts)
|
||||||
host = config["host"] == "127.0.0.1" ? "localhost" : config["host"]
|
server_address(
|
||||||
port = config["port"]
|
config["ssl_cert"] && config["ssl_key"],
|
||||||
protocol = config["ssl_cert"] && config["ssl_key"] ? "https" : "http"
|
config["host"] == "127.0.0.1" ? "localhost" : config["host"],
|
||||||
"#{protocol}://#{host}:#{port}"
|
config["port"]
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue