Skip to content

Commit 1a1b249

Browse files
committed
Add host: parameter to PreviewAction.init
Now that `PreviewServer` requires an explicit host name, we should require one here too instead of hardcoding `localhost`.
1 parent 62c24f5 commit 1a1b249

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Sources/SwiftDocCUtilities/Action/Actions/PreviewAction.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public final class PreviewAction: Action, RecreatingContext {
5353

5454
var logHandle = LogHandle.standardOutput
5555

56+
let host: String
5657
let port: Int
5758

5859
var convertAction: ConvertAction
@@ -75,6 +76,7 @@ public final class PreviewAction: Action, RecreatingContext {
7576
/// Creates a new preview action from the given parameters.
7677
///
7778
/// - Parameters:
79+
/// - host: The host name used by the preview server.
7880
/// - port: The port number used by the preview server.
7981
/// - convertAction: The action used to convert the documentation bundle before preview.
8082
/// On macOS, this action will be reused to convert documentation each time the source is modified.
@@ -84,6 +86,7 @@ public final class PreviewAction: Action, RecreatingContext {
8486
/// is performed.
8587
/// - Throws: If an error is encountered while initializing the documentation context.
8688
public init(
89+
host: String,
8790
port: Int,
8891
createConvertAction: @escaping () throws -> ConvertAction,
8992
workspace: DocumentationWorkspace = DocumentationWorkspace(),
@@ -95,6 +98,7 @@ public final class PreviewAction: Action, RecreatingContext {
9598
}
9699

97100
// Initialize the action context.
101+
self.host = host
98102
self.port = port
99103
self.createConvertAction = createConvertAction
100104
self.convertAction = try createConvertAction()
@@ -108,13 +112,14 @@ public final class PreviewAction: Action, RecreatingContext {
108112
@available(*, deprecated, message: "TLS support has been removed.")
109113
public convenience init(
110114
tlsCertificateKey: URL?, tlsCertificateChain: URL?, serverUsername: String?,
111-
serverPassword: String?, port: Int,
115+
serverPassword: String?, host: String, port: Int,
112116
createConvertAction: @escaping () throws -> ConvertAction,
113117
workspace: DocumentationWorkspace = DocumentationWorkspace(),
114118
context: DocumentationContext? = nil,
115119
printTemplatePath: Bool = true) throws
116120
{
117121
try self.init(
122+
host: host,
118123
port: port,
119124
createConvertAction: createConvertAction,
120125
workspace: workspace,
@@ -165,15 +170,15 @@ public final class PreviewAction: Action, RecreatingContext {
165170
print(String(repeating: "=", count: 40), to: &logHandle)
166171
var components = URLComponents()
167172
components.scheme = "http"
168-
components.host = "localhost"
173+
components.host = host
169174
components.port = port
170175
if let previewURL = components.url {
171176
print("Starting Local Preview Server", to: &logHandle)
172177
printPreviewAddresses(base: previewURL)
173178
print(String(repeating: "=", count: 40), to: &logHandle)
174179
}
175180

176-
let to: PreviewServer.Bind = bindServerToSocketPath.map { .socket(path: $0) } ?? .localhost(host: "localhost", port: port)
181+
let to: PreviewServer.Bind = bindServerToSocketPath.map { .socket(path: $0) } ?? .localhost(host: host, port: port)
177182
servers[serverIdentifier] = try PreviewServer(contentURL: convertAction.targetDirectory, bindTo: to, logHandle: &logHandle)
178183

179184
// When the user stops docc - stop the preview server first before exiting.

Sources/SwiftDocCUtilities/ArgumentParsing/ActionExtensions/PreviewAction+CommandInitialization.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extension PreviewAction {
2424
{
2525
// Initialize the `PreviewAction` from the options provided by the `Preview` command
2626
try self.init(
27+
host: "localhost",
2728
port: previewOptions.port,
2829
createConvertAction: {
2930
try ConvertAction(

0 commit comments

Comments
 (0)