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)
|
||||
server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
|
||||
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"]
|
||||
boot_or_detach server, opts
|
||||
end
|
||||
|
@ -124,23 +129,25 @@ module Jekyll
|
|||
#
|
||||
|
||||
private
|
||||
def server_address(server, opts)
|
||||
def server_address(prefix, address, port, baseurl = nil)
|
||||
format("%{prefix}://%{address}:%{port}%{baseurl}", {
|
||||
:prefix => server.config[:SSLEnable] ? "https" : "http",
|
||||
:baseurl => opts["baseurl"] ? "#{opts["baseurl"]}/" : "",
|
||||
:address => server.config[:BindAddress],
|
||||
:port => server.config[:Port]
|
||||
:prefix => prefix ? "https" : "http",
|
||||
:address => address,
|
||||
:port => port,
|
||||
:baseurl => baseurl ? "#{baseurl}/" : ""
|
||||
})
|
||||
end
|
||||
|
||||
#
|
||||
|
||||
private
|
||||
def default_url(opts)
|
||||
config = configuration_from_options(opts)
|
||||
host = config["host"] == "127.0.0.1" ? "localhost" : config["host"]
|
||||
port = config["port"]
|
||||
protocol = config["ssl_cert"] && config["ssl_key"] ? "https" : "http"
|
||||
"#{protocol}://#{host}:#{port}"
|
||||
server_address(
|
||||
config["ssl_cert"] && config["ssl_key"],
|
||||
config["host"] == "127.0.0.1" ? "localhost" : config["host"],
|
||||
config["port"]
|
||||
)
|
||||
end
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue