Added (first version of) sample Hummingbird app. #3
+15
-15
@@ -3,7 +3,7 @@
|
|||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: DocCMiddleware.package,
|
name: HummingbirdDocC.package,
|
||||||
platforms: [
|
platforms: [
|
||||||
.iOS(.v17),
|
.iOS(.v17),
|
||||||
.macCatalyst(.v17),
|
.macCatalyst(.v17),
|
||||||
@@ -13,8 +13,8 @@ let package = Package(
|
|||||||
],
|
],
|
||||||
products: [
|
products: [
|
||||||
.library(
|
.library(
|
||||||
name: DocCMiddleware.package,
|
name: HummingbirdDocC.package,
|
||||||
targets: [DocCMiddleware.target]
|
targets: [HummingbirdDocC.target]
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
@@ -24,12 +24,12 @@ let package = Package(
|
|||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.executableTarget(
|
.executableTarget(
|
||||||
name: DocCMiddleware.sample,
|
name: HummingbirdDocC.sample,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.byName(name: DocCMiddleware.target),
|
.byName(name: HummingbirdDocC.target),
|
||||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||||
],
|
],
|
||||||
path: "Samples/DocCMiddleware",
|
path: "Samples/HummingbirdDocC",
|
||||||
swiftSettings: [
|
swiftSettings: [
|
||||||
// Enable better optimizations when building in Release configuration. Despite the use of
|
// Enable better optimizations when building in Release configuration. Despite the use of
|
||||||
// the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
|
// the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
|
||||||
@@ -38,29 +38,29 @@ let package = Package(
|
|||||||
]
|
]
|
||||||
),
|
),
|
||||||
.target(
|
.target(
|
||||||
name: DocCMiddleware.target,
|
name: HummingbirdDocC.target,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.product(name: "Hummingbird", package: "hummingbird"),
|
.product(name: "Hummingbird", package: "hummingbird"),
|
||||||
],
|
],
|
||||||
path: "Sources/DocCMiddleware",
|
path: "Sources/HummingbirdDocC",
|
||||||
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
|
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
|
||||||
),
|
),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: DocCMiddleware.test,
|
name: HummingbirdDocC.test,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.product(name: "HummingbirdTesting", package: "hummingbird"),
|
.product(name: "HummingbirdTesting", package: "hummingbird"),
|
||||||
.byName(name: DocCMiddleware.target)
|
.byName(name: HummingbirdDocC.target)
|
||||||
],
|
],
|
||||||
path: "Tests/DocCMiddleware"
|
path: "Tests/HummingbirdDocC"
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|
||||||
enum DocCMiddleware {
|
enum HummingbirdDocC {
|
||||||
static let package = "hummingbird-docc"
|
static let package = "hummingbird-docc"
|
||||||
static let sample = "\(DocCMiddleware.target)Sample"
|
static let sample = "\(HummingbirdDocC.target)Sample"
|
||||||
static let target = "DocCMiddleware"
|
static let target = "HummingbirdDocC"
|
||||||
static let test = "\(DocCMiddleware.target)Test"
|
static let test = "\(HummingbirdDocC.target)Test"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
// ===----------------------------------------------------------------------===
|
||||||
|
//
|
||||||
|
// This source file is part of the Hummingbird DocC Middleware open source project
|
||||||
|
//
|
||||||
|
// Copyright (c) 2025 Röck+Cöde VoF. and the Hummingbird DocC Middleware project authors
|
||||||
|
// Licensed under the EUPL 1.2 or later.
|
||||||
|
//
|
||||||
|
// See LICENSE for license information
|
||||||
|
// See CONTRIBUTORS for the list of Hummingbird DocC Middleware project authors
|
||||||
|
//
|
||||||
|
// ===----------------------------------------------------------------------===
|
||||||
|
|
||||||
|
import class Hummingbird.Router
|
||||||
|
|
||||||
|
import protocol Hummingbird.ApplicationProtocol
|
||||||
|
|
||||||
|
import struct Hummingbird.Application
|
||||||
|
import struct Hummingbird.BindAddress
|
||||||
|
import struct Logging.Logger
|
||||||
|
|
||||||
|
struct AppBuilder {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
/// A type that interacts with the logging system.
|
||||||
|
private let logger: Logger
|
||||||
|
|
||||||
|
// MARK: Initializers
|
||||||
|
|
||||||
|
/// Initializes this builder.
|
||||||
|
/// - Parameter logger: A type that interacts with the logging system.
|
||||||
|
init(logger: Logger) {
|
||||||
|
self.logger = logger
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
func callAsFunction(
|
||||||
|
_ arguments: AppArguments
|
||||||
|
) -> some ApplicationProtocol {
|
||||||
|
let router = Router()
|
||||||
|
|
||||||
|
return Application(
|
||||||
|
router: router,
|
||||||
|
configuration: .init(
|
||||||
|
address: .hostname(arguments.hostname, port: arguments.port)
|
||||||
|
),
|
||||||
|
logger: logger
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,10 @@
|
|||||||
//
|
//
|
||||||
// ===----------------------------------------------------------------------===
|
// ===----------------------------------------------------------------------===
|
||||||
|
|
||||||
|
import protocol ArgumentParser.AsyncParsableCommand
|
||||||
|
|
||||||
import struct ArgumentParser.OptionGroup
|
import struct ArgumentParser.OptionGroup
|
||||||
|
import struct Logging.Logger
|
||||||
|
|
||||||
/// A type that implements and runs the sample executable that showcases the `Hummingbird-DocC` middleware.
|
/// A type that implements and runs the sample executable that showcases the `Hummingbird-DocC` middleware.
|
||||||
@main struct SampleApp {
|
@main struct SampleApp {
|
||||||
@@ -22,3 +25,24 @@ import struct ArgumentParser.OptionGroup
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - AsyncParsableCommand
|
||||||
|
|
||||||
|
extension SampleApp: AsyncParsableCommand {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
func run() async throws {
|
||||||
|
let builder = AppBuilder(logger: {
|
||||||
|
var logger = Logger(label: "sample.hummingbird-docc.logger")
|
||||||
|
|
||||||
|
logger.logLevel = arguments.logLevel ?? .trace
|
||||||
|
|
||||||
|
return logger
|
||||||
|
}())
|
||||||
|
|
||||||
|
let application = builder(arguments)
|
||||||
|
|
||||||
|
try await application.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
import Testing
|
import Testing
|
||||||
|
|
||||||
@testable import enum DocCMiddleware.AssetFile
|
@testable import enum HummingbirdDocC.AssetFile
|
||||||
|
|
||||||
@Suite("Asset File", .tags(.enumeration))
|
@Suite("Asset File", .tags(.enumeration))
|
||||||
struct AssetFileTests {
|
struct AssetFileTests {
|
||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
import Testing
|
import Testing
|
||||||
|
|
||||||
@testable import enum DocCMiddleware.AssetFolder
|
@testable import enum HummingbirdDocC.AssetFolder
|
||||||
|
|
||||||
@Suite("Asset Folder", .tags(.enumeration))
|
@Suite("Asset Folder", .tags(.enumeration))
|
||||||
struct AssetFolderTests {
|
struct AssetFolderTests {
|
||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
import Testing
|
import Testing
|
||||||
|
|
||||||
@testable import enum DocCMiddleware.DocumentationFolder
|
@testable import enum HummingbirdDocC.DocumentationFolder
|
||||||
|
|
||||||
@Suite("Documentation Type", .tags(.enumeration))
|
@Suite("Documentation Type", .tags(.enumeration))
|
||||||
struct DocumentationTypeTests {
|
struct DocumentationTypeTests {
|
||||||
+1
-1
@@ -17,7 +17,7 @@ import struct Hummingbird.HTTPResponse
|
|||||||
import struct Hummingbird.Request
|
import struct Hummingbird.Request
|
||||||
import struct Logging.Logger
|
import struct Logging.Logger
|
||||||
|
|
||||||
@testable import DocCMiddleware
|
@testable import HummingbirdDocC
|
||||||
|
|
||||||
@Suite("Logger Metadata Helpers", .tags(.extension))
|
@Suite("Logger Metadata Helpers", .tags(.extension))
|
||||||
struct LoggerMetadata_HelpersTests {
|
struct LoggerMetadata_HelpersTests {
|
||||||
+1
-1
@@ -14,7 +14,7 @@ import Testing
|
|||||||
|
|
||||||
import struct HummingbirdCore.URI
|
import struct HummingbirdCore.URI
|
||||||
|
|
||||||
@testable import struct DocCMiddleware.CheckURIUseCase
|
@testable import struct HummingbirdDocC.CheckURIUseCase
|
||||||
|
|
||||||
@Suite("Check URI use case", .tags(.useCase))
|
@Suite("Check URI use case", .tags(.useCase))
|
||||||
struct CheckURIUseCaseTests {
|
struct CheckURIUseCaseTests {
|
||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
import Testing
|
import Testing
|
||||||
|
|
||||||
@testable import struct DocCMiddleware.PrepareURIPathUseCase
|
@testable import struct HummingbirdDocC.PrepareURIPathUseCase
|
||||||
|
|
||||||
@Suite("Prepare URI Path Use Case", .tags(.useCase))
|
@Suite("Prepare URI Path Use Case", .tags(.useCase))
|
||||||
struct PrepareURIPathUseCaseTests {
|
struct PrepareURIPathUseCaseTests {
|
||||||
+1
-1
@@ -18,7 +18,7 @@ import struct Hummingbird.HTTPResponse
|
|||||||
import struct Hummingbird.Request
|
import struct Hummingbird.Request
|
||||||
import struct Logging.Logger
|
import struct Logging.Logger
|
||||||
|
|
||||||
@testable import struct DocCMiddleware.RedirectURIUseCase
|
@testable import struct HummingbirdDocC.RedirectURIUseCase
|
||||||
|
|
||||||
@Suite("Redirect URI Use Case", .tags(.useCase))
|
@Suite("Redirect URI Use Case", .tags(.useCase))
|
||||||
struct RedirectURIUseCaseTests {
|
struct RedirectURIUseCaseTests {
|
||||||
+1
-1
@@ -18,7 +18,7 @@ import struct Hummingbird.HTTPResponse
|
|||||||
import struct Hummingbird.Request
|
import struct Hummingbird.Request
|
||||||
import struct Logging.Logger
|
import struct Logging.Logger
|
||||||
|
|
||||||
@testable import struct DocCMiddleware.ServeURIUseCase
|
@testable import struct HummingbirdDocC.ServeURIUseCase
|
||||||
|
|
||||||
@Suite("Serve URI Use Case", .tags(.useCase))
|
@Suite("Serve URI Use Case", .tags(.useCase))
|
||||||
struct ServeURIUseCaseTests {
|
struct ServeURIUseCaseTests {
|
||||||
+1
-1
@@ -20,7 +20,7 @@ import struct Hummingbird.LocalFileSystem
|
|||||||
import struct Hummingbird.Request
|
import struct Hummingbird.Request
|
||||||
import struct Logging.Logger
|
import struct Logging.Logger
|
||||||
|
|
||||||
@testable import struct DocCMiddleware.DocCMiddleware
|
@testable import struct HummingbirdDocC.DocCMiddleware
|
||||||
|
|
||||||
@Suite("DocC Middleware", .tags(.middleware))
|
@Suite("DocC Middleware", .tags(.middleware))
|
||||||
struct DocCMiddlewareTests {
|
struct DocCMiddlewareTests {
|
||||||
Reference in New Issue
Block a user