Improved the initializers for the DocCMiddleware type in the library target.
This commit is contained in:
@@ -10,20 +10,21 @@
|
||||
//
|
||||
// ===----------------------------------------------------------------------===
|
||||
|
||||
import Hummingbird
|
||||
import protocol Hummingbird.FileProvider
|
||||
|
||||
import struct Hummingbird.LocalFileSystem
|
||||
import struct Logging.Logger
|
||||
|
||||
/// A middleware that proxies requests to `DocC` documentation containers within a hosting app.
|
||||
public struct DocCMiddleware {
|
||||
public struct DocCMiddleware<FileSystemProvider: FileProvider> {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
/// A type that contains the parameters to configure the middleware.
|
||||
let configuration: Configuration
|
||||
|
||||
/// A protocol that defines file system interactions.
|
||||
let fileProvider: any FileProvider
|
||||
/// A type that conforms to a protocol that defines file system interactions.
|
||||
let fileProvider: FileSystemProvider
|
||||
|
||||
/// A type that interacts with the logging system.
|
||||
let logger: Logger
|
||||
@@ -33,27 +34,44 @@ public struct DocCMiddleware {
|
||||
|
||||
// MARK: Initializers
|
||||
|
||||
/// Initializes this middleware with the root path to the `DocC` documentation containers in the file system.
|
||||
/// Initializes this middleware.
|
||||
/// - Parameters:
|
||||
/// - configuration: A type that contains the parameters to configure the middleware.
|
||||
/// - logger: A type that interacts with the logging system.
|
||||
/// - fileProvider: A type that conforms to the protocol that defines file system interactions, if any.
|
||||
init(
|
||||
public init(
|
||||
configuration: Configuration,
|
||||
logger: Logger,
|
||||
fileProvider: (any FileProvider)? = nil
|
||||
) {
|
||||
self.configuration = configuration
|
||||
self.fileProvider = if let fileProvider {
|
||||
fileProvider
|
||||
} else {
|
||||
LocalFileSystem(
|
||||
logger: Logger
|
||||
) where FileSystemProvider == LocalFileSystem {
|
||||
self.init(
|
||||
configuration: configuration,
|
||||
fileProvider: LocalFileSystem(
|
||||
rootFolder: configuration.folderRoot,
|
||||
threadPool: configuration.threadPool,
|
||||
logger: logger
|
||||
)
|
||||
}
|
||||
),
|
||||
logger: logger,
|
||||
)
|
||||
}
|
||||
|
||||
/// Initializes this middleware with a concrete file provider type.
|
||||
/// - Parameters:
|
||||
/// - configuration: A type that contains the parameters to configure the middleware.
|
||||
/// - fileProvider: A type that conforms to the protocol that defines file system interactions.
|
||||
/// - logger: A type that interacts with the logging system.
|
||||
init(
|
||||
configuration: Configuration,
|
||||
fileProvider: FileSystemProvider,
|
||||
logger: Logger,
|
||||
) {
|
||||
self.logger = logger
|
||||
self.configuration = configuration
|
||||
self.fileProvider = fileProvider
|
||||
self.prepareURIPath = .init(uriRoot: configuration.uriRoot)
|
||||
self.redirectURI = .init(logger: logger)
|
||||
self.serveURI = .init(
|
||||
fileProvider: fileProvider,
|
||||
logger: logger
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user