File tree Expand file tree Collapse file tree 3 files changed +51
-6
lines changed
Examples/HelloWorldHummingbird Expand file tree Collapse file tree 3 files changed +51
-6
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ let package = Package(
2121 platforms: [ . macOS( . v14) ] ,
2222 dependencies: [
2323 . package ( url: " https://github.com/hummingbird-project/hummingbird.git " , from: " 2.1.0 " ) ,
24- . package ( url: " https://github.com/apple/swift-container-plugin " , from: " 0.4.0 " ) ,
24+ . package ( url: " https://github.com/apple/swift-container-plugin " , from: " 0.5.0 " ) ,
25+ . package ( url: " https://github.com/apple/swift-argument-parser " , from: " 1.3.0 " ) ,
2526 ] ,
2627 targets: [
2728 . executableTarget( name: " hello-world " , dependencies: [ . product( name: " Hummingbird " , package : " hummingbird " ) ] )
Original file line number Diff line number Diff line change 1+ //===----------------------------------------------------------------------===//
2+ //
3+ // This source file is part of the SwiftContainerPlugin open source project
4+ //
5+ // Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
6+ // Licensed under Apache License v2.0
7+ //
8+ // See LICENSE.txt for license information
9+ // See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
10+ //
11+ // SPDX-License-Identifier: Apache-2.0
12+ //
13+ //===----------------------------------------------------------------------===//
14+
15+ import ArgumentParser
16+
17+ @main
18+ struct Hello : AsyncParsableCommand {
19+ @Option ( name: . shortAndLong)
20+ var hostname : String = " 0.0.0.0 "
21+
22+ @Option ( name: . shortAndLong)
23+ var port : Int = 8080
24+
25+ func run( ) async throws {
26+ let app = buildApplication (
27+ configuration: . init(
28+ address: . hostname( hostname, port: port) ,
29+ serverName: " Hummingbird "
30+ )
31+ )
32+ try await app. runService ( )
33+ }
34+ }
Original file line number Diff line number Diff line change 22//
33// This source file is part of the SwiftContainerPlugin open source project
44//
5- // Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
5+ // Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
66// Licensed under Apache License v2.0
77//
88// See LICENSE.txt for license information
1414
1515import Foundation
1616import Hummingbird
17+ import Logging
1718
1819let myos = ProcessInfo . processInfo. operatingSystemVersionString
1920
20- let router = Router ( )
21- router. get { request, _ -> String in " Hello World, from Hummingbird on \( myos) \n " }
21+ func buildApplication( configuration: ApplicationConfiguration ) -> some ApplicationProtocol {
22+ let router = Router ( )
23+ router. addMiddleware { LogRequestsMiddleware ( . info) }
24+ router. get ( " / " ) { _, _ in
25+ " Hello World, from Hummingbird on \( myos) \n "
26+ }
2227
23- let app = Application ( router: router, configuration: . init( address: . hostname( " 0.0.0.0 " , port: 8080 ) ) )
28+ let app = Application (
29+ router: router,
30+ configuration: configuration,
31+ logger: Logger ( label: " HelloWorldHummingbird " )
32+ )
2433
25- try await app. runService ( )
34+ return app
35+ }
You can’t perform that action at this time.
0 commit comments