Skip to content

Commit 96d74ea

Browse files
committed
Examples: Adopt structure used in Vapor template
1 parent 3fa1d83 commit 96d74ea

File tree

4 files changed

+61
-10
lines changed

4 files changed

+61
-10
lines changed

Examples/HelloWorldVapor/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ let package = Package(
2020
name: "hello-world",
2121
platforms: [.macOS(.v13)],
2222
dependencies: [
23-
.package(url: "https://github.com/vapor/vapor", .upToNextMajor(from: "4.102.0")),
24-
.package(url: "https://github.com/apple/swift-container-plugin", from: "0.4.0"),
23+
.package(url: "https://github.com/vapor/vapor", from: "4.102.0"),
24+
.package(url: "https://github.com/apple/swift-container-plugin", from: "0.5.0"),
2525
],
2626
targets: [.executableTarget(name: "hello-world", dependencies: [.product(name: "Vapor", package: "vapor")])]
2727
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 Vapor
16+
17+
func configure(_ app: Application) async throws {
18+
try routes(app)
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 Vapor
16+
17+
@main
18+
enum Entrypoint {
19+
static func main() async throws {
20+
let env = try Environment.detect()
21+
let app = try await Application.make(env)
22+
app.http.server.configuration.hostname = "0.0.0.0"
23+
24+
do {
25+
try await configure(app)
26+
try await app.execute()
27+
} catch {
28+
app.logger.report(error: error)
29+
try? await app.asyncShutdown()
30+
throw error
31+
}
32+
try await app.asyncShutdown()
33+
}
34+
}

Examples/HelloWorldVapor/Sources/main.swift renamed to Examples/HelloWorldVapor/Sources/routes.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
@@ -17,10 +17,8 @@ import Vapor
1717

1818
let myos = ProcessInfo.processInfo.operatingSystemVersionString
1919

20-
let app = try Application(.detect())
21-
app.http.server.configuration.hostname = "0.0.0.0"
22-
defer { app.shutdown() }
23-
24-
app.get { _ in "Hello World, from Vapor on \(myos)\n" }
25-
26-
try app.run()
20+
func routes(_ app: Application) throws {
21+
app.get { req async in
22+
"Hello World, from Vapor on \(myos)\n"
23+
}
24+
}

0 commit comments

Comments
 (0)