File tree Expand file tree Collapse file tree 3 files changed +80
-49
lines changed
Examples/HelloWorldWithResources/Sources Expand file tree Collapse file tree 3 files changed +80
-49
lines changed 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
+ @main
16
+ struct Hello {
17
+ static let hostname = " 0.0.0.0 "
18
+ static let port = 8080
19
+
20
+ static func main( ) async throws {
21
+ let app = buildApplication (
22
+ configuration: . init(
23
+ address: . hostname( hostname, port: port) ,
24
+ serverName: " Hummingbird "
25
+ )
26
+ )
27
+ try await app. runService ( )
28
+ }
29
+ }
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
+ let faces = [
26
+ " happy-cat-face " ,
27
+ " slightly-smiling-face " ,
28
+ " smiling-face-with-sunglasses " ,
29
+ ]
30
+
31
+ guard let resourceURL = Bundle . module. url ( forResource: faces. randomElement ( ) , withExtension: " jpg " ) else {
32
+ throw HTTPError ( . internalServerError)
33
+ }
34
+
35
+ let image = try Data ( contentsOf: resourceURL)
36
+
37
+ return Response (
38
+ status: . ok,
39
+ headers: [ . contentType: " image/jpg " ] ,
40
+ body: . init( byteBuffer: ByteBuffer ( bytes: image) )
41
+ )
42
+ }
43
+
44
+ let app = Application (
45
+ router: router,
46
+ configuration: configuration,
47
+ logger: Logger ( label: " hello-with-resources " )
48
+ )
49
+
50
+ return app
51
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments