File tree Expand file tree Collapse file tree 3 files changed +58
-7
lines changed
Examples/HelloWorldHummingbird Expand file tree Collapse file tree 3 files changed +58
-7
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,16 @@ let package = Package(
21
21
platforms: [ . macOS( . v14) ] ,
22
22
dependencies: [
23
23
. 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 " ) ,
25
26
] ,
26
27
targets: [
27
- . executableTarget( name: " hello-world " , dependencies: [ . product( name: " Hummingbird " , package : " hummingbird " ) ] )
28
+ . executableTarget(
29
+ name: " hello-world " ,
30
+ dependencies: [
31
+ . product( name: " Hummingbird " , package : " hummingbird " ) ,
32
+ . product( name: " ArgumentParser " , package : " swift-argument-parser " ) ,
33
+ ]
34
+ )
28
35
]
29
36
)
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 2
2
//
3
3
// This source file is part of the SwiftContainerPlugin open source project
4
4
//
5
- // Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
5
+ // Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
6
6
// Licensed under Apache License v2.0
7
7
//
8
8
// See LICENSE.txt for license information
14
14
15
15
import Foundation
16
16
import Hummingbird
17
+ import Logging
17
18
18
19
let myos = ProcessInfo . processInfo. operatingSystemVersionString
19
20
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
+ }
22
27
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
+ )
24
33
25
- try await app. runService ( )
34
+ return app
35
+ }
You can’t perform that action at this time.
0 commit comments