File tree Expand file tree Collapse file tree 2 files changed +52
-8
lines changed
Examples/HelloWorldHummingbird/Sources Expand file tree Collapse file tree 2 files changed +52
-8
lines changed Original file line number Diff line number Diff line change 1212//
1313//===----------------------------------------------------------------------===//
1414
15- import Foundation
16- import Hummingbird
15+ import ArgumentParser
1716
18- let myos = ProcessInfo . processInfo. operatingSystemVersionString
17+ @main
18+ struct Hello : AsyncParsableCommand {
19+ @Option ( name: . shortAndLong)
20+ var hostname : String = " 0.0.0.0 "
1921
20- let router = Router ( )
21- router . get { request , _ -> String in " Hello World, from Hummingbird on \( myos ) \n " }
22+ @ Option ( name : . shortAndLong )
23+ var port : Int = 8080
2224
23- let app = Application ( router: router, configuration: . init( address: . hostname( " 0.0.0.0 " , port: 8080 ) ) )
24-
25- try await app. runService ( )
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 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 Foundation
16+ import Hummingbird
17+ import Logging
18+
19+ let myos = ProcessInfo . processInfo. operatingSystemVersionString
20+
21+ func buildApplication( configuration: ApplicationConfiguration ) -> some ApplicationProtocol {
22+ let router = Router ( )
23+ router. addMiddleware { LogRequestsMiddleware ( . info) }
24+ router. get ( " / " ) { _, _ in
25+ return " Hello World, from Hummingbird on \( myos) \n "
26+ }
27+
28+ let app = Application (
29+ router: router,
30+ configuration: configuration,
31+ logger: Logger ( label: " HelloWorldHummingbird " )
32+ )
33+
34+ return app
35+ }
You can’t perform that action at this time.
0 commit comments